Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Spaces in file path

by gvinu4u (Acolyte)
on Jul 07, 2011 at 16:12 UTC ( [id://913217]=perlquestion: print w/replies, xml ) Need Help??

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

In the below code when I have only the file name it works fine but when I have the entire path it fails to give me the file contents. Please help me in this issue.
#!/user/bin/perl open (FH, "d:\Swalpa Development kaliri ....Sir\WorkSpace\Perl\CMD_Fil +e.txt"); @array = <FH>; print @array ; close FH ;
The issue is that I need to get rid of the spaces in the path I tried replacing as below but still it did not work. d:\Swalpa/Development/kaliri/....Sir\WorkSpace\Perl\CMD_File.txt

Replies are listed 'Best First'.
Re: Spaces in file path
by Corion (Patriarch) on Jul 07, 2011 at 16:15 UTC

    If you used warnings, Perl would tell you what goes wrong:

    > perl -we "my $filename = qq(d:\Swalpa Development kaliri ....Sir\Wor +kSpace\Perl\CMD_File.txt);" Unrecognized escape \S passed through at -e line 1. Unrecognized escape \W passed through at -e line 1. Unrecognized escape \P passed through at -e line 1. Unrecognized escape \C passed through at -e line 1.

    A backslash is a special character in (double-quoted) strings. See perlop.

      Thanks a lot changed \ to / and now it works.
Re: Spaces in file path
by nimdokk (Vicar) on Jul 08, 2011 at 12:07 UTC
    Instead of using double guotes, try single quotes so Perl does not interpolate the backslash directory seperators. You may also find File::Spec useful. Just my 2¢.

Log In?
Username:
Password:

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

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

    No recent polls found