in reply to Re: Searching within compressed files
in thread Searching within compressed files
Since I'm a big fan of both lexical filehandles, and the safer forms of piping open, here's a version that uses both of those:
use strict; use warnings; open my $infh, "-|", zcat => $myfile or die "Cannot open file: $myfile\n"; while (<$infh>) { print if /mymatch/; }
This avoids using a global filehandle, and would allow you to take the filename in as a command line argument, without worrying about escaping nasty characters. I think it's a pretty big benefit for a fairly small change in the code.
|
|---|