![]() |
|
There's more than one way to do things | |
PerlMonks |
Re^2: get n lines before or after a patternby johngg (Abbot) |
on Jul 25, 2012 at 23:54 UTC ( #983752=note: print w/replies, xml ) | Need Help?? |
Reading "records" rather than lines is a nice approach. One minor point, your local is not really local as you have not confined it to a particular scope so it applies from the point it appears until the end of the script. Rather than the split and array slice, another approach could be to open a file handle against a reference to the record so that you can read it line by line in an inner scope and just print the lines you want. This has the advantage that the record layout can change and it will still work.
I hope this is of interest. Cheers, JohnGG
In Section
Seekers of Perl Wisdom
|
|