in reply to Re^3: extract and export to multiple files
in thread extract and export to multiple files

Thank you so much. Actually I started reading the Llama book although I am not a frequent user of Perl. However, I anticipate I will be using regular expression a lot in future. Speaking of regular expression, how can I match ampersand in a character set? I was trying to match "DESIGN & PLAN:" or "DESIGN/PLAN:" or "DESIGN PLAN" with [A-Z &\/]+[:|;] but this doesnot match the first variation. I have thousands of "titles" that are all in upper case and may consist of one or more words that may end in ":" or ";" It seems matching special characters in a character set is different and basically everything except "-" as in A-Z is treated as non-special character but for some reason it does not match "&" in my regex. Thanks again for all the hints.

Replies are listed 'Best First'.
Re^5: extract and export to multiple files
by GrandFather (Saint) on Apr 10, 2010 at 05:09 UTC

    Show me some sample code that fails. It works as expected for me:

    use strict; use warnings; for my $str ("DESIGN & PLAN:", "DESIGN/PLAN:", "DESIGN PLAN") { print "Matched $str\n" if $str =~ /^[A-Z &\/]+[:|;]/; }

    Prints:

    Matched DESIGN & PLAN: Matched DESIGN/PLAN:

    The last string doesn't match because there isn't a trailing colon or semi-colon.

    True laziness is hard work
      Thank you Grandfather. It turned out CR and LF were the problem in that specific file that contained ampersand character. The text files are coming from an IBM mainframe with Mac(LF) encoding. By the way, I had to preprocess and remove "/" from $titles before running your script since they are not accepted as a valid character in a file name. I converted them into "OR"! Thank you again for your great assistance.