Thread: Perl Programing

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    2
    Rep 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 Quers

    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?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    842
    Rep Power
    496
    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.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0
    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?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    842
    Rep Power
    496
    Add the /d modifier to the tr/// command. Characters 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.
  8. #5
  9. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSn
    Posts
    6,898
    Rep Power
    3887
    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;

    Comments on this post

    • Laurent_R agrees

IMN logo majestic logo threadwatch logo seochat tools logo