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

Fellow Monks,

I'm using Win32::FileOp to map a drive, but I want to use a variable instead of the actual ip address, but can't seem to get it to play nicely. This works:
Map G => '\\\\192.168.21.15\\c$', { persistent => 1 };
but this doesn't:
my $ip = 'shift'; my $share = '\\\\' . $ip . '\\c$'; Map G => $share, { persistent => 1 };
Any helps is much appreciated.

-Dru

Replies are listed 'Best First'.
Re: Using Win32::FileOp to Map a Drive by Variable
by runrig (Abbot) on Oct 19, 2005 at 19:17 UTC
    The literal word 'shift' is not a valid IP address. Do you really have single quotes around the word? Checking the value of your variables is the first step to debugging (e.g. printing the value of $share would've told you the problem).
      Yup, you're right, I looked at the code 50 times before posting, because I hate when I miss stupid things like this, and I missed it. I also agree I should have printed out "$share". Thanks for the (hard) lesson learned.

        Hint: use a syntax-hilighting editor. It will help make things like this more obvious. As to which one to use - that's the subject of many a religious war, so I won't go there. There are many available, and which ones are "best" will be solely determined by the way you work. Since switching to a syntax-hilighting editor, I've never gone back.