in reply to I think I'm starting to get it

Actually, Perl doesn't reinterpolate strings. Two backslashes should be enough. This sounds like a bug.

As an example, if I do: $str= "C:\\Windows" and then try to use $str in a regular expression: if(  $path =~ /^$str/i  ) { then this won't work. But that is because I made a mistake. I should have written: if(  $path =~ /^\Q$str\E/i  ) { to tell the regular expression that I wanted it to parse $str as a string and not as a regular expression. (I also made a mistake in trying to use a regular expression to compare file paths as the resulting code is not portable.)

I have a hard time coming up with cases other than regular expressions and eval where it is easy to get Perl to interpolate a string a second time. Perhaps you could do some more digging and find where this second interpolation is happening so that a fix could be made (or so I could understand why it isn't a bug in this case).

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re: I think I'm starting to get it
by cLive ;-) (Prior) on Apr 04, 2001 at 23:49 UTC
    Am I missing something...
    $str= quotemeta 'C:\Windows'; if ( $path =~ /^$str/i ) { ...
    or...

    is that not a bit easier on the eyes :)

    As long as you use single quotes for $str it can stay readable...

    cLive ;-)

      That is (mostly) fine too.

      I prefer to tell the regex that I want it to treat the string as a string rather than transform the string into a regex that matches the old string, but most of my freinds know that I'm wierd.

      I also find that getting in the habit of using a single \ inside of single quotes is likely to bite you when you get used to it and try '\\server\share\dir' and can't figure out why you aren't finding those files.

              - tye (but my friends call me "Tye")
Re: (tye)Re: I think I'm starting to get it
by extremely (Priest) on Apr 05, 2001 at 02:33 UTC
    Perl doesn't reinterpolate often but sometimes shells are involved when DBI calls are set up. Maybe that is where the issue is?

    --
    $you = new YOU;
    honk() if $you->love(perl)

Re: (tye)Re: I think I'm starting to get it
by coolmichael (Deacon) on Apr 10, 2001 at 10:53 UTC
    As I was working on getting DBD::CSV to work on my Windows98 maching with ActiveState Perl 5.6.0, I had some problems. $connectstr="C:\Windows\Desktop" didn't work. I got an error along the lines of "C:indowsesktop not found." (sorry, can't remember the actual error, but that's the gist of it. So then I put in an extra set of quotes $connectstr="C:\\Windows\\Desktop" and got the same error. So, after trying a few hundred different things, I got it to work with single quotes. I figured if it worked with single quotes, then putting more backslashes infront of the existing backslashes would work inside double quotes, which it did. Unfortunatly, I still don't know why it works.

    I looked into CSV.pm. It uses prototypes, which I don't get yet, and I don't have my camel handy. sub connect ($$;$$$) means (I think) two scalars, followed by three optional scalars. &DBD::CSV::connect() doesn't have a regex in it, but it does call &DBD::File::dr::connect() which does use a regex (one that is *way* beyond me now), which is where the problem comes from.

    I think that makes it not a bug, but something strange that isn't documented in DBD::CSV as far as I can tell.

    What do you think? Does any of this make sense?

    michael
    the blue haired monk