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¢.