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

Thank you so much for your great help. So while the output of the split remains in the default variable ,$_, what does 2 do? Also, how can I manipulate $. variable in a way that sequential numbers being added to the $title and not to the file extension: I am getting file.txt1 instead of file1.txt I tried ".txt" after ".$" but obviously didn't work Thanks again for your explanations and help
  • Comment on Re^2: extract and export to multiple files

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

    I strongly recommend that you follow the links (did I make them too subtle?) and read the documentation. In fact spending a few hours browsing the documentation that came with Perl and a few more hours reading some of the Perl tutorial and reference books ("Learning Perl" and "Programming Perl" at least) will save you days of beating your head against the desk if you intend to use Perl regularly. There are some good recommendations in the So what is your Perl book "Trilogy" anyway? thread. Visiting the Tutorials section is well worth doing too.

    I followed the pattern you gave (">$filename"."$title"."$count") for forming the file name. The sequence number following the file name is what you would have got in your original code. If you want to put it before the last '.' then you need to edit the file name string. Something like the following in place of the original $outpath assignment ought do the trick:

    my $outpath = "$outdir/$title"; $outpath =~ s/(\.[^.]*|)$/$.$1/;

    You will definitely want to read some of the documentation for regular expressions: perlrequick and perlretut at least (there is more).

    True laziness is hard work
      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.

        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
Re^3: extract and export to multiple files
by umasuresh (Hermit) on Apr 09, 2010 at 14:49 UTC