Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: compressing VERY LARGE files

by RMGir (Prior)
on Sep 26, 2002 at 20:10 UTC ( #201033=note: print w/replies, xml ) Need Help??

in reply to compressing VERY LARGE files

Don't give up on bzip2 or gzip just because they may not always be in the same place.

It may be simpler to write a routine to find the executable and run it than to get a module installed across all of those machines... If you can guarantee that at least gzip is on all the boxes, it shouldn't be too hard, in fact...

sub findCompressor { my @paths=( "/usr/bin". "/bin", "/usr/local/bin", "/usr/share/bin", "/opt/bin", "$ENV{HOME}/bin", "$ENV{HOME}/local/bin", ); foreach my $prog('bzip2','gzip','compress') { foreach my $dir(@paths) { my $path="$dir/$prog"; return $path if -x $path; } } # return some default non-compressing compressor?? } # run once my $compressor=findCompress();
Not sure if that makes sense in your case, but I think it would work...

Replies are listed 'Best First'.
Re: Re: compressing VERY LARGE files
by gnu@perl (Pilgrim) on Sep 26, 2002 at 20:14 UTC
    Thanks, I really had not thought of that. What I might do is write the location of the compression binary to a file once I find it, then check that file first each time to be sure it is still there, if not, just look for it again.

      Glad you like it :)

      But I wouldn't save the location to a file.

      Imagine a very bare bones server, where only compress is installed. Your script runs once, saves /bin/compress as the preferred compressor, and never notices the next week when bzip is installed. (It could also have trouble if the executable was moved or deleted...)

      Compared with compressing a 600M file, I wouldn't worry about the overhead of doing (at most!) 21 -x's once each time your script starts up...

Re: Re: compressing VERY LARGE files
by duelafn (Vicar) on Sep 27, 2002 at 13:26 UTC
    Many linux boxes also have the which command, so this could be simplified to,
    my $prog; for (qw/bzip2 gzip compress/) { chomp($prog = qx|which $_|); last if $prog; } print "Found: $prog\n";
      As gnu@perl said in his original post, the compression binaries may not be in the user's path.

      which tells you where a program lies on your path, "which" may not help in this case... It could be added as an additional test, though.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://201033]
[marto]: good morning all

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2017-12-11 10:46 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (289 votes). Check out past polls.