Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Reading the name of a file in a .gz

Reply
Thread Tools

Reading the name of a file in a .gz

 
 
Yoda Pugsley
Guest
Posts: n/a
 
      04-08-2004
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
 
Reply With Quote
 
 
 
 
Jim Gibson
Guest
Posts: n/a
 
      04-08-2004
In article <Xns94C59E1CBDCEBheretherecom@65.32.1.8>, Yoda Pugsley
<(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
adding a variable name to a hash to name is part of the variable name Bobby Chamness Perl 2 04-22-2007 09:54 PM
print("my name is {name}, and {age}-year old {gender}", name, age, gender); =?iso-8859-1?B?bW9vcJk=?= Java 7 01-02-2006 04:39 PM
IE name="name" & form.name property bug Java script Dude Javascript 5 06-30-2004 03:07 AM
name = name.substring(0, name.lastIndexOf('.')); Help please Jack-2 Javascript 3 12-24-2003 04:39 PM
Re: Urgent! how to get object name, method name and attribute name based on the strings? ding feng C++ 2 06-25-2003 01:18 PM



Advertisments