Special_K has asked for the wisdom of the Perl Monks concerning the following question:
I have a script that needs to be able to operate on either a plain text file or a gzipped version of that file. If the file is not gzipped, the file will be opened as follows:
open(FOO, $foo) || die("ERROR: Unable to open file $foo for read: $!") +;
If the file is gzipped, the file will be opened as follows:
open(FOO, "zcat $foo |") || die("ERROR: Unable to open gzipped file $f +oo for read: $!");
How do I write a check to determine whether the file is gzipped or not? zcat errors out when called on non-gzipped files.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to test if a file is gzipped or not
by sectokia (Friar) on Jun 17, 2024 at 23:25 UTC | |
by soonix (Chancellor) on Jun 18, 2024 at 07:35 UTC | |
|
Re: How to test if a file is gzipped or not
by LanX (Saint) on Jun 17, 2024 at 22:09 UTC | |
|
Re: How to test if a file is gzipped or not
by Tux (Canon) on Jun 18, 2024 at 08:51 UTC | |
|
Re: How to test if a file is gzipped or not
by eyepopslikeamosquito (Archbishop) on Jun 18, 2024 at 09:38 UTC | |
|
Re: How to test if a file is gzipped or not
by jwkrahn (Abbot) on Jun 17, 2024 at 22:06 UTC | |
by Happy-the-monk (Canon) on Jun 18, 2024 at 07:42 UTC | |
by choroba (Cardinal) on Jun 18, 2024 at 08:19 UTC | |
|
Re: How to test if a file is gzipped or not
by Anonymous Monk on Jun 17, 2024 at 23:43 UTC |