in reply to Re^2: Piping many individual files into a single perl script
in thread Piping many individual files into a single perl script
I like BrowserUk's solution below, except that I'd probably rewrite it (I mostly didn't like the chained if-elsif's) in a manner similar to (untested:)
#/usr/bin/perl use strict; use warnings; use 5.010; BEGIN{ @ARGV=map glob, @ARGV } print "File Number A A% B B% Null Null%"; my $default = ''; # set to something sensible, the empty string seems + good. my @allowed = (qw/stringa stringb/, $default); my (%count, $filenum); while(<>) { chomp; $count{$_ ~~ @allowed ? $_ : $default}++; if (eof) { $filenum++; say "$filenum ", join ' ' => map { my $x=$count{$_}; $x, sprintf('%.2f', $x/1000) } @allo +wed; @count{@allowed}=(0) x @allowed; } } __END__
I threw in some 5.10-isms in the course of doing so, but it wouldn't be terribly different with pre-5.10 exists.
|
---|