in reply to Re^2: read and write file in directory
in thread read and write file in directory

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.

Replies are listed 'Best First'.
Re^4: read and write file in directory
by Corion (Patriarch) on Dec 01, 2014 at 13:14 UTC

    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.

      and using that string within regular expressions (without quotemeta) will also get the value interpreted anew

      You're right of course. The situation where I encountered the problem -- probably 12 or more years ago -- was almost certainly with regex.

      But since I switched to using /s instead of \s everywhere (except when passing stuff to the shell), I haven't had the problem; so I hope you'll excuse me if the long distance memory confused the circumstances :)


      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.