in reply to Backslashes in command arguements

It would probably be useful to print out $hostName before you use it. Your double backslash on the command line ("foo.pl \\hostname") may be converted to a single backslash when Perl gets it, but I'm guessing that it's getting converted in the backticks. You can escape them before it gets there like so:

$hostName =~ s/\\/\\\\/g;

Update: Thanks to ikegami for pointing out that my speculation was off the mark. DOS does not mangle backslashes on the command line. I thought it might, so I suggested printing out the variable to be sure. I'd have checked this myself, but I don't have Perl on Windows to try.

Replies are listed 'Best First'.
Re^2: Backslashes in command arguements
by ikegami (Patriarch) on Feb 26, 2007 at 17:24 UTC

    Your double backslash on the command line ("foo.pl \\hostname") may be converted to a single backslash when Perl gets it

    No.

    >perl -e "print $ARGV[0]" \\hostname \\hostname

    If there's a slash missing, it was removed *before* Perl got it.