Pointers - pass args to subroutines, don't rely on globals. Second, don't name a filehandle DATA, because there is already a built-in DATA filehandle. Third, use a regex on a scalar that contains the file contents, not a for loop on an array.
Check this out:
See perlre for more info on regexes and the 's' option and perlop for info on 'qr'.use strict; my $contents = do {local $/; <DATA>}; print get_chunk($contents); sub get_chunk { my ($contents) = @_; my $start = qr|========= Summary of bfpr_catfl results ===\s*|; my $end = qr|========= end ===\s*|; my ($chunk) = $contents =~ /$start(.*)$end/s; return $chunk; } __DATA__ you won't see this or this ========= Summary of bfpr_catfl results === you will see this and this ========= end === you won't see this or this or that
UPDATE:
I notice you tend to group variables together with a common
prefix - BFPRCONS - you should try a global hash (not all
globals are bad):
my %BFPRCONS = ( filename => 'whatever_the_name_is', count => 0, start => qr|===== summary blah ===|, end => qr|===== end blah ===|, ); # then you could inc the count like so: $BFPRCONS{'count'}++; # you could set the file name like so: $BFPRCONS{'filename'} = join ('_',$job,$junk1,$etc);
jeffa
L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
F--F--F--F--F--F--F--F--
(the triplet paradiddle)
In reply to (jeffa) Re: Stupid parsing question
by jeffa
in thread Stupid parsing question
by dew
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |