in reply to Re: block extraction
in thread block extraction

Thank you for the hints. I started like below but I guess I'm way off! Do you suggest to go another direction? Thank you for the help

open IN, "." || "die, can't open";
undef($/);
$string=<IN>;
$string=~m/(^Processing\s\d+\.tx\.\d+:)(.*?)(^Phrase:)(.*?)(Meta Mapping)(.*?)(\n)/g;
print "$2\t$4\t$6";
exit;

Replies are listed 'Best First'.
Re^3: block extraction
by hbm (Hermit) on Feb 04, 2009 at 14:42 UTC

    Here's a simple example to open the file and print out the records. When you understand this, you can begin to manipulate the records before printing.

    use strict; use warnings; my $file = "t.txt"; $/="\n\n"; open IN, "<", $file or die "Unable to open $file: $!"; while(<IN>){ print "=======\n", $_, "=======\n\n"; } close IN;
      Thank you hbm

        Note hbm's use of strictures - always use strictures (use strict; use warnings;).

        Also notice that hbm used the three parameter version of open and checked the result of the open by using very low precedence or rather than high precedence || which checks to see if the last parameter is true or not (not what you are wanting I suspect).

        There are a couple of changes I'd make though. Use local to localize the effect of changing special variables ($/ in this case) and use a lexical file handle:

        ... local $/="\n\n"; open my $inFile, "<", $file or die "Unable to open $file: $!"; while(<$inFile>){ ...

        Perl's payment curve coincides with its learning curve.