Practical extracting and reporting

jplindstrom on 2002-09-05T20:57:27

I rarely use Perl for what Perl was originally (like in the 16:th century or something) built for; extracting and reporting. But today I did. And it was cool in all it's simplicity and usefulness.

Read through some files based on a filename regexp, identify the file, find some values, and summarize them in a table using MoinMoin (it's a Wiki) formatting. 20 minutes, including blocking some values, and providing aliases for some, and tweaking the table formatting. No longer than it would have taken me to do it manually, only: * It wasn't boring * It was correct, no chance to slip up * It can be done again at any time with updated files.

Oh, the joy of small scale automation :)

BTW, I also re-coded my canonical read-contents-of-a-file for the n:th time (I tend to do that in sooo many small scripts).

sub loadFile { my ($file) = @_; local $/; open(my $fh, $file) or return(""); return(<$fh>); }

File::Slurp isn't in the distribution, right? Well... it should.


IO::File perhaps?

broquaint on 2002-09-06T12:15:30

You could use IO::File for your slurp
use IO::File;

my @lines = IO::File->new(shift)->getlines;
Or something not entirely dissimilar to that.