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

Tried changing the ENV{'PATH'} variable to my direcotry, but still getting errors. I.e. set path to '/home/mysite', then system "gzip test.doc" = error
  • Comment on How do I Set the Correct Path for system calls?

Replies are listed 'Best First'.
Re: How do I Set the Correct Path for system calls?
by lestrrat (Deacon) on Jul 17, 2001 at 11:03 UTC

    This may be a moot point if you *really* couldn't find out where your gzip program is, but shouldn't it sort of scare you to just call an external program without specifying the absolute path to it?

    I personally REALLY don't like relying on PATH when you are calling something from a script.

    Of course, it may not make that much of a difference, but I would recommend hardcoding the location in your script. Maybe

    <cdde> my $gzip_cmd = '/usr/local/bin/gzip'; # or use vars qw/ $gzip_cmd/ ; # global # or %cmds = ( gzip => '/usr/local/bin/gzip' ); </code>

    Or some such thing. Just my $0.02

Re: How do I Set the Correct Path for system calls?
by Zaxo (Archbishop) on Jul 17, 2001 at 04:22 UTC

    You're clobbering the rest of $ENV{'PATH'}, in particular "/usr/bin:/bin". Use $ENV{'PATH'} .= ':/home/mysite';.