In article <Xns94C59E1CBDCEBheretherecom@65.32.1.8>, Yoda Pugsley
<> wrote:
> Hello,
>
> I need to read the name of a file inside a .gz. I know it should be the
> zipped name - .gz, but the filenames are long and truncated sometimes. In
> perl, what is the command to read the gzip -l into a variable? Something
> like
>
>
> my ($filename)
>
> $filename == gzip -l ~/cdr/file.gz
>
> will that work, or something like it?
>
> Thanks,
> JH
The following might work, provided your gzip program produces two lines
of output with the file name in the fourth field of the second line:
#!/usr/local/bin/perl
use strict;
use warnings;
my $f = 'file.gz';
$_ = (`gzip -l $f`)[1];
my $filename = (split)[3];
print "filename: $filename\n";
FYI: this newsgroup is defunct. Try comp.lang.perl.misc in the future.
|