The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Perl Programming
|
Perl Programing
Discuss Perl Programing in the Perl Programming forum on Dev Shed. Perl Programing Perl Programming forum discussing coding in Perl, utilizing Perl modules, and other Perl-related topics. Perl, the Practical Extraction and Reporting Language, is the choice for many for parsing textual information.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 20th, 2013, 12:42 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 2
Time spent in forums: 6 m 4 sec
Reputation Power: 0
|
|
|
Perl Programing
TRMMMYQ128F932D901<SEP>SOQMMHC12AB0180CB8<SEP>Faster ***** cat<SEP>Silent Night
TRMMMKD128F425225D<SEP>SOVFVAK12A8C1350D9<SEP>Karkkiautomaatti<SEP>Tanssi vaan
TRMMMRX128F93187D9<SEP>SOGTUKN12AB017F4F1<SEP>Hudson Mohawke<SEP>No One Could Ever
TRMMMCH128F425532C<SEP>SOBNYVR12A8C13558C<SEP>Yerba Brava<SEP>Si Vos Querés
TRMMMWA128F426B589<SEP>SOHSBXH12A8C13B0DF<SEP>Der Mystic<SEP>Tangle Of Aspens
what would be the regular expression to take out just the last part of the above sentences?
how should i remove the special characters in those extracted part?
and how should i convert them to lower case letters?
|

February 20th, 2013, 02:06 PM
|
|
|
Hi,
a starting point:
Code:
my $value = $1 if $line =~/<SEP>(\w+)$/;
$value = lc $value;
$value =~tr/àéèùçôê/aeeucoe/;
You will probably want to beef up the tr// substitution list, this is just an example.
|

February 20th, 2013, 02:12 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 2
Time spent in forums: 6 m 4 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by Laurent_R Hi,
a starting point:
Code:
my $value = $1 if $line =~/<SEP>(\w+)$/;
$value = lc $value;
$value =~tr/àéèùçôê/aeeucoe/;
You will probably want to beef up the tr// substitution list, this is just an example. |
so if i want to remove special characters like (,[{,',@ how will the expression be like?
|

February 21st, 2013, 02:33 AM
|
|
|
|
Add the /d modifier to the tr/// command. Charaécters havinf no substitutes un ther substitution list will be removed. For example:
$value =~tr/àéèùçôê;%/aeeucoe/d;
Here, the ";" and the "%" will be removed from the string, while other letters will be replaced by their respective substitutes.
|

February 21st, 2013, 05:48 AM
|
 |
kill 9, $$;
|
|
Join Date: Sep 2001
Location: Shanghai, An tSín
|
|
Quote: | Originally Posted by abhibitu so if i want to remove special characters like (,[{,',@ how will the expression be like? |
The definition of a "special character" is usually far more complex than you might expect (since there is a huge number of characters to consider). It's often easier to identify characters that you want to keep, and then remove those that are not in that set of desired characters.
You can use the /c switch on tr/// to complement the search list (i.e. replace any characters that AREN'T in the search list). For example, to remove any non-alphanumeric characters in a string called $str you could use this:
Code:
$str =~ tr/a-zA-Z0-9//cd;
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|