See here for unformatted version that you can save.
package mycommon;
use strict;
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION);
use Exporter;
$VERSION=1.00;
@ISA= qw(Exporter);
@EXPORT = qw (zcat min max);
@EXPORT_OK = qw (zcat min max);
%EXPORT_TAGS = ();
sub zcat {
my (@files) = (@_);
my (@res,$file);
my ($strip,$noact);
if ($files[0] eq "--strip") {
$strip=shift @files;
}
$noact = !wantarray;
local *FHI;
foreach $file (@files) {
my $type=`file "$file"`;
$type =~ /gzip compressed data/ &&
(open(FHI, "gzip -dc \"$file\"|") or die "Can't open gzip -dc \"$file\" for read") ||
$type =~ /bzip2 compressed data/ &&
(open(FHI, "bzip2 -dc \"$file\"|") or die "Can't open gzip -dc \"$file\" for read") ||
do {
if ($noact) {
return undef; }
(open(FHI, "$file") or die "Can't open $file for read");
};
if ($noact) {
return *FHI; }
while (<FHI>) {
defined($strip) && chomp;
push @res, $_;
}
close FHI;
}
return @res;
}
sub min {
my ($min,$i);
$min=(@_)[0];
for $i (@_) {
if ($i < $min) {
$min=$i;
}
}
return $min;
}
sub max {
my ($max,$i);
$max=(@_)[0];
for $i (@_) {
if ($i > $max) {
$max=$i;
}
}
return $max;
}
1;