in reply to read and write file in directory

Change this: $pathName="$dir\\$fileName"; to this: $pathName="$dir/$fileName";


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: read and write file in directory
by vinoth.ree (Monsignor) on Dec 01, 2014 at 12:58 UTC

    may be he is on windows. As per his script it looks like windows path. I am not sure. he has to tell us.


    All is well
      may be he is on windows

      Doesn't matter. All the windows APIs (and thus all of Perl's) accept / as a path separator.

      The problem with his use of \\ is that whilst doubling the backslashes works when he constructs the string, when he interpolates it into another string, the double backslash has been reduced to a single backslash, so it gets seen as escaping the next character in the string and disappears completely.

      All windows/perl users should be aware and use / in preference to \ for paths, it makes life much easier.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Hmm - no, interpolation doesn't work the way I interpret your post:

        my $backslash= '\\'; print "This is a backslash: ->$backslash<-\n"; print "Two backslashes: ->$backslash$backslash<-\n"; print "Two backslashes and a 't' (not a tab): ->$backslash${backslash} +t<-\n"; print "One backslash and a 't' (not a tab): ->${backslash}t<-\n"; __END__ This is a backslash: ->\<- Two backslashes: ->\\<- Two backslashes and a 't' (not a tab): ->\\t<- One backslash and a 't' (not a tab): ->\t<-

        So once a backslash has been stored in a variable, interpolating that variable into other values won't trigger escape sequences. eval will do, and using that string within regular expressions (without quotemeta) will also get the value interpreted anew, evaluating escape sequences.

        Still, from a viewpoint of compatibility, as long as you don't have to pass the filenames to outside programs, using forward slash instead of backslash is still preferrable.