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

Re^2: While is not working when using variable

by parthodas (Acolyte)
on Aug 31, 2015 at 08:47 UTC ( [id://1140508]=note: print w/replies, xml ) Need Help??


in reply to Re: While is not working when using variable
in thread While is not working when using variable

On using autodie, it is showing the error message that no such file or directory. But when harcoding the same path, the script is running.
Can't open('FILE', '$filename'): No such file or directory at sblmaint.pl
  • Comment on Re^2: While is not working when using variable

Replies are listed 'Best First'.
Re^3: While is not working when using variable
by Eily (Monsignor) on Aug 31, 2015 at 08:57 UTC

    Try this:

    print '$filename', "\n"; print "$filename", "\n";

    And for more information, you can read this tutorial on quotes in perl.

      This helped a lot. Using double quote and double slash resolved the issue. Thanks a lot.
Re^3: While is not working when using variable
by soonix (Canon) on Aug 31, 2015 at 14:46 UTC
    In addition to Eilys hint, try
    print $filename, "\n";
    Note that, if you have your complete filename in a variable, like in your OP (and as you should, as it eases debugging and error messages), quoting it in the open statement is superfluous.

    Besides, most Windows functions and many programs accept forward slashes, so you can write

    my $filename="$mydir/file_detail.txt"; open (FILE, "<", $filename);
    Update: corrected quotes - d'oh! Thanks AnomalousMonk!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1140508]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-25 21:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found