Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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...
--
Mike


Comment on Re: compressing VERY LARGE files
Download Code
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...
      --
      Mike

Re: Re: compressing VERY LARGE files
by duelafn (Priest) 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.
      --
      Mike

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://201033]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2014-08-30 03:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls