Perl: the Markov chain saw | |
PerlMonks |
Re: Subsetting text files containing e-mailsby GrandFather (Saint) |
on Jan 25, 2012 at 09:52 UTC ( [id://949860]=note: print w/replies, xml ) | Need Help?? |
To an extent you can translate bash into Perl. The control structures (if and loops) translate without much trouble. Many of the system utilities that you'd be using in your bash script have Perl equivalents, although they aren't drop in replacements and you are right to guess there are better ways in Perl than the pipelined filter processing technique you likely used with bash. With Perl you will tend more to parse through the input file essentially a line at a time to find the "interesting bits" and generate output as you go. The thing is to be able to recognise an interesting bit before you have moved on to the next line. Perl has a neat trick that makes that pretty easy in your case. I apologise in advance for spoilers - the following is most of the solution you need so more than you asked for:
Prints:
See perlvar for a description of what $/ is doing.
True laziness is hard work
In Section
Seekers of Perl Wisdom
|
|