Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Perl Program works on local machine, not over network?

by jdlev (Scribe)
on Jan 31, 2012 at 18:43 UTC ( #951037=perlquestion: print w/ replies, xml ) Need Help??
jdlev has asked for the wisdom of the Perl Monks concerning the following question:

I'm having an issue simply opening a file and having perl output it on the screen when I run it in the command prompt.

Basically...if I put the file in the same folder as my .pl script, and run it...it works fine.

However, when I change the location to say something like this:
$loc = '\\Server\Shared Folder\Text.txt'; I can't get it to read it?
Here's my code...what am I doing wrong?:

print "ENTER ACCOUNT NUMBER: "; $acct = <>; print "\n>SEARCHING FOR DISPATCH INSTRUCTIONS ON ACCOUNT #: $acct Ple +ase Wait..."; $loc = "\\\\Server\\MappedNetworkDrive\\Folder\\$acct\\DispatchInstruc +tions.txt"; print $loc; #Get File Info open(MYFILE, "$loc") or print "Didn't Open $loc"; while (<MYFILE>) { sleep(5); chomp; print "$_\n"; } close (MYFILE);
I love it when a program comes together - jdhannibal

Comment on Perl Program works on local machine, not over network?
Download Code
Re: Perl Program works on local machine, not over network?
by toolic (Chancellor) on Jan 31, 2012 at 19:08 UTC
    $acct will have a newline in it. chomp it.
    print "ENTER ACCOUNT NUMBER: "; $acct = <>; chomp $acct;
      Worked Great...THANKS BIG TIME! YOU GET MY VOTE :)
      I love it when a program comes together - jdhannibal
Re: Perl Program works on local machine, not over network?
by dasgar (Deacon) on Jan 31, 2012 at 19:12 UTC

    A couple of suggestions to help you get more help from perl itself:

      1.)  Add use strict; and use warnings; at the start of your scripts. Of course, this will cause you to need to use my the first time that you use a variable.

      2.)  Modify you line of code where you open the file to print out a more useful error message by changing it to:

    open(MYFILE, "$loc") or print "Didn't Open $loc: $!\n";

    With more useful warning and error messages, it will be easier for you (and others) to debug the issue(s).

      Even better with the open is to use the three parameter variant and lexical file handles:

      open my $inFile, '<', $sloc or die "Can't open $loc: $!\n";

      which makes the open mode explicit (and avoids a potential injection attack), and gives all the strictly goodness advantages from using the lexical file handle.

      Oh, and don't interpolate a single variable ("$loc") - there is no need and clutters the code.

      True laziness is hard work

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://951037]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2014-07-25 23:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls