[kw-pm] Using backticks in Perl script

Quantum Mechanic quantum.mechanic.1964 at gmail.com
Mon Feb 8 06:46:57 PST 2010


On Tue, Feb 2, 2010 at 10:19 AM, Robert Pike <roberthpike at yahoo.com> wrote:

> Hi All,
>   I've been passed a script that does unzipping of files and I can't seem
> to get it to work on a Windows machine. The server I'm trying this on I have
> to VPN in to. I've commented out the code that is trying to unzip a file and
> decided to put a simplier command in and see if I can get that to work but
> still w/o success.
>
>   my $testStr = "dir";   #--- line 1
>   my $newTest = `$testStr`;
>   print "<br>Test string returned :" . $newTest . "<br>";
>
>   When I run the overall script I get errors on the third line of code
> above telling me <name of script.pl>: Use of uninitialized value $newTest
> in concatenation (.) or string at <name of script>.pl line 82.
>   I'm trying this simplier example to see if I can get it working first,
> the piece of code in the script (I was passed) is trying to use the gunzip
> executable but w/o success (i.e. gunzip -cf <$filePath) using the backticks
> again. Any help would be appreciated. Thanks.
>

"dir" is a builtin command, and doesn't exist anywhere as an executable by
default. On my XP machine, I'd have to issue

     cmd /c "dir"

You would have the same problem on *nix with builtins if the shell didn't
interpret them. For instance, `setenv` does nothing when called from perl,
though it does from the command line.

(However, I doubt that this is your original problem -- most likely you've
created an unrelated problem by trying to make the script simpler.)

-- 
-QM
Quantum Mechanics: The dreams stuff is made of
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/kw-pm/attachments/20100208/3ba31612/attachment.html>


More information about the kw-pm mailing list