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

I want use a file from sharedDrive I'm trying to point to that and it's giving me error I'm using following code to doit
#!/usr/bin/perl $drvname="//shareddrive/directory/"; open (IN,"<$drvname/filename) or die "can't open file: $!\n"; . . . . exit 0;
I checked all names that is shareddrive name and also directory and file name, they all are correct. I also tried $drvname="/shareddrive/directory" and also $drvname="shareddrive/directory" nothing worked.. Please give me any suggestion

Replies are listed 'Best First'.
Re: Sharedrive and Perl
by zzspectrez (Hermit) on Nov 04, 2000 at 06:57 UTC

    If this is a windows share, then you are refrencing it wrong. I had the same problem when I tried to access a file on my local network. Here is a simple sample that I wrote and tested on my local Windows network.


    Oh, and about the shebang line. Some people leave it for windows scripts for a few reasons. Portability of course. And even with strictly windows code, I leave because it tells my editor that the document is perl code to do syntax hilighting corectly!!


    #!/usr/bin/perl -w use strict; my $share_path = '\\\\Zoe\\zoe_data\\'; my $test_file = 'test.txt'; open (INP, $share_path . $test_file) or die "Can't open file [$share_path . $test_file]: $!\n"; while (<INP>){ print; } close (INP);

    zzspectrez
Re: Sharedrive and Perl
by Trimbach (Curate) on Nov 04, 2000 at 03:29 UTC
    Closing your quotes might help (i.e., ("<$drvname/filename") not ("<$drivename/filename) as above)

    What kind of error is "die" giving you? That should be a big clue if that isn't the problem.

    Gary Blackburn
    Trained Killer

      I did use right syntax. it was typo when I put there here.anyways it's giving me error saying it can not aceess path I have described.sharedrive is on my network.and perl files are in c:/perl/bin. I'm trying to get files from share drive and use my perl script to get data out of those files using perl script from c:/perl/bin everything works ok until i come to the point where i'm trying to get data out of files from sharedrive.the path and filename is correct.may be there's another way to access sharedrive???
Re: Sharedrive and Perl
by curtisb (Monk) on Nov 04, 2000 at 04:26 UTC
    If you are using a shared drive under a Windows OS, you may want to try and use the drive letter in your $drvname variable.
    $drvname="//shareddrive/directory/";
    Might work if you write it like this:
    $drvname="Z:/shareddrive/directory/";
    I agree with the others on the other items.
    curtisb
RE: Sharedrive and Perl
by AgentM (Curate) on Nov 04, 2000 at 03:50 UTC
    I'm getting some mixed messages here, Anish. at first, it appears that you are running this perl script using the executable in /usr/bin/perl which clearly indicates UN*X or a derivative thereof (since there is no real 'root' directory in the family of quality Microsoft products). Then, I see that you are using the standard WinSMB method of snatching a share from a host computer aptly named "sharedDrive". Other than closing your quotes, you might want to double-czech which OS you're running. Under UN*X, your '//' will never do what you want it to do. Perhaps if you supply more information or if you read up on the topic at hand, like open(), then you'll manage to fix the problem yourself.
    AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.

      I start all of my scripts with "#!/usr/bin/perl", even if they will only work under Win32. No reason to switch to a different she-bang line and for the many scripts that are portable, having a proper shebang line can come in handy.

              - tye (but my friends call me "Tye")
Re: Sharedrive and Perl
by JP Sama (Hermit) on Nov 04, 2000 at 22:33 UTC
    I don't know if your problem has been solved... or not.. but i believe, you would never open a file using:
    "//shareddrive/directory//filename" ... at least this would be the address that you are referencing above...
    #!/jpsama/bin/perl -w
    $tks = `mount`;
    $jpsama = $! if $!;
    print $jpsama;