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

This qusetion is similar to one I had put here on friday. I'm trying to use file from sharedrive on my local network I'm using following code
#! /usr/bin/perl $drvSwift= "G:/directoryname/Swift"; open (IN,"<$drvSwift/filename") or die "can't open the file: $!\n";
this works because my sharedrive is maped to G: on my PC, now I want to use sharedrive name instead, i.e $drvSwift="sharedrive/directoryname/Swift";so people who wants to use my code and have access to sharedrive, dont have to change the code to put in drivename to which this sharedrive is mapped to on their PC. but everytime they run it it points to that Sharedrive, Disregarding where this sharedrive is mapped to on thier PC.is it possible? if it is, what is the syntax?? Thanks for help.

Replies are listed 'Best First'.
(tye)Re: Perl and Shared drive
by tye (Sage) on Nov 06, 2000 at 22:00 UTC

    This should work:

    $drvSwift= "//machine/share/subdir/Swift";
    The only thing I can think is that you were leaving off the machine name?

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

Re: Perl and Shared drive
by Fastolfe (Vicar) on Nov 06, 2000 at 22:00 UTC
    Have you tried using the standard way?
    open(IN, "< //system/share/dir/filename") or die "...";
Re: Perl and Shared drive
by wardk (Deacon) on Nov 06, 2000 at 22:06 UTC

    This simple example just worked for me on Win98:

    #!/usr/bin/perl my @files = `dir \\\\MACHINE\\SHARENAME`; foreach ( @files ) { print; } exit;
      In my experience the above is the most reliable way to do this.

      $drive = "\\\\servername\\path"

      The quad backslashes being the key point here..
        I tried this too.suppose my servername is nj7001pdcpublic, there is directory SAPTreasTeam. then there is subdorectory under SAPTreasTeam called swift. how would you access this in perl.
RE: Perl and Shared drive
by zzspectrez (Hermit) on Nov 06, 2000 at 23:20 UTC

    Your question is a little vague. If you are trying to write you script so that other people can run the script on their computer without having to modify it, then you need to refer to the file by its network path. Instead of referring to the mapped drive name use the share name.

    Example
    '\\\\ComputerName\\DirName\\Filename' or
    '//ComputerName/Dirname/Filename'

    Here is some example code I tested on my computer of different ways to access the data.

    #! /usr/bin/perl -w # Different ways to open file on another networked windows machine. # Assume: Other computers name is Zoe # The file is in the shared directory zoe_data\test # The directory zoe_data has been mapped localy to F: # The filename is test.txt @mypaths = ( '\\\\Zoe\\zoe_data\\test\\', 'F:\\test\\', '//Zoe/zoe_data/test/', 'F:/test/' ); $filename = "test.txt"; foreach $path (@mypaths) { print "\n\nOpening file [", $path . $filename, " ]\n\n"; open (IN,$path . $filename) or die "can't open the file: $!\n"; print while (<IN>); close (IN); }

    I hope this answers your question.
    zzspectrez

      I tried this too.suppose my servername is nj7001pdcpublic, there is directory SAPTreasTeam. then there is subdorectory under SAPTreasTeam called SWIFT.and file under that subdirectory called Swift. how would you access this in perl.I tried
      $drvSwift="//nj7001pdcpublic/SAPTreasTeam/SWIFT/Swift";
      it's not working any suggestions.

        Ok. You need to be more specific. What is not working. What is the rest of the code. What is the error returned. What type of file.

        Couple things come to mind. First of, do you have privelages to access the file? With Win98 you can set passwords for shares. With Win2k and NT files have privelages.

        If this is not the problem. The biggest thing that comes to mind looking at that path is what kind of file is it?? You have no file extension. Most files in the windows world have a file extension but they are not shown by windows. For example, if it was a text document in would be swift.txt if a word document swift.doc or if it was excel document swift.xls. Could you be accidently forgetting something simple as a file extension??

        Hope that helps!
        zzspectrez