Coplan has asked for the wisdom of the Perl Monks concerning the following question:

Super Search ain't helpin' me today =(

I'm working on a perl script that requires me to actually unzip a file to check its contents. If at all possible, I'd like to prevent the output from displaying, as I intend to parse the output. Here's my line of code (all variables have been declared, and what-not:

my $unzip_output = system("unzip -l $filename");

Thanks, --Coplan

Replies are listed 'Best First'.
Re: preventing a system call from displaying output
by arhuman (Vicar) on Feb 16, 2001 at 12:43 UTC

    why don't you use backquote ?

    Something like :

    my $unzip_output = `unzip -l $filename`;
Re: preventing a system call from displaying output
by extremely (Priest) on Feb 16, 2001 at 12:47 UTC
    yeah, my $uzlist=`unzip -l $filename`); should do what you want. Or godforbid you use a module or something. (Actually, I guess, that Archive::Zip has a pretty low version number so you may wanna keep shelling out for PKZip files. Looks rather complete to me, OTOH =) If you are doing GZips or Tar files you will be happier with these well kept modules tho, Archive::Tar and Compress::Zlib.

    --
    $you = new YOU;
    honk() if $you->love(perl)

      Version numbers don't mean anything. I've been meaning to make the version of Archive-Zip 1.0 sometime soon; perhaps I'll do this on the version that is now known as 0.12 . A::Z is and has been quite stable.
Re: preventing a system call from displaying output
by stefan k (Curate) on Feb 16, 2001 at 13:53 UTC
    Another way would be to redirect the output:

    system("unzip -l $filename > /dev/null");

    If you need to you can redirect STDERR, too ...

    Regards Stefan K

Re: preventing a system call from displaying output
by chipmunk (Parson) on Feb 16, 2001 at 19:30 UTC
Re: preventing a system call from displaying output
by oakley (Scribe) on Feb 16, 2001 at 17:47 UTC
    If you are wanting to parse the output of what zip gives (and yes the others have touched on this already) you could try:
    my $tmpfile = POSIX::tmpnam(); system("unzip -l $filename 2>$tmpfile"); open(OUTPUT, "$tmpfile") || die "Cant open $tmpfile file, $!\n"; while(<OUTPUT>) { ... do something here ... } close(OUTPUT);
    - oakley
    Embracing insanity - one twitch at a time >:)
Re: preventing a system call from displaying output
by zigster (Hermit) on Feb 16, 2001 at 19:38 UTC
    Open a file handle to it.
    open FHAND,"unzip -l $filename|"; while(<FHAND>) { # PROCESS $_ }

    --

    Zigster