in reply to Perl - Read a file on another server

I think there may be a problem with your filename. Aren't the slashes supposed to be backslashes?
open(FH, "<\\\\Server2\\f\$\\logconn.txt") || die("Can't open file! ($!)\n");
should do the trick. Didn't try it here, though.

All Camels are equal, but some Camels are more equal than others.

Replies are listed 'Best First'.
Re: Re: Perl - Read a file on another server
by eejack (Hermit) on May 05, 2001 at 04:22 UTC
    Howdy jink,

    The filename was quoted with single quote marks...
    $file = '//Server2/f$/logconn.txt';
    which would be fine. However if he were using double quote marks like then you would be correct. Also interesting to not that the direction of the slashes make no real difference on win32 perl.

    $file = '//Server2/f$/logconn.txt'; and $file = '\\Server2\f$l\logconn.txt';
    are equivalent.

    EEjack

      $file = '//Server2/f$/logconn.txt';
      and
      $file = '\\Server2\f$\logconn.txt';

      are equivalent.

      (I removed the "l" typo)
      Try this:

      print '//Server2/f$/logconn.txt', $/; print '\\Server2\f$\logconn.txt', $/;
      and you'll see
      //Server2/f$/logconn.txt \Server2\f$\logconn.txt
      Use that second one as a file path and Server2 won't even be bothered.

      This is why I always double \ in Perl quoted strings (except for "here documents" which is the one form of quoting in Perl that doesn't treat \ as special) and so would write the second one as: '\\\\Server2\\f$\\logconn.txt' even when using single quotes. Otherwise you get in the habit of thinking that \ isn't special in single quotes and make the mistake you just did (which can be real hard to debug when you do it).

      P.S. Note that / doesn't work as a directory separator when you pass file names as command-line arguments to many Win32 commands. I believe that this is the only exception (well, other than some GUI tools don't allow them either, but most people rarely use Perl to stuff strings into a GUI [though I've done that]).

              - tye (but my friends call me "Tye")