Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

regex error

by anaconda_wly (Scribe)
on Apr 06, 2013 at 10:12 UTC ( #1027274=perlquestion: print w/ replies, xml ) Need Help??
anaconda_wly has asked for the wisdom of the Perl Monks concerning the following question:

I got error in regex: Sequence \k... not terminated in regex; marked by <-- HERE in m/"c:\qa\k <-- HERE onductor\bin"/ at...
$binpath="c:\\qa\\kontor\\bin"; if( $ENV{PATH} !~ /$binpath/i) # error here
It's OK when I type directly not using a string var.
if( $ENV{PATH} !~ /c:\\qa\\kontor\\bin/i)
Anyone can point out my error?Thanks

Comment on regex error
Select or Download Code
Replies are listed 'Best First'.
Re: regex error
by aitap (Deacon) on Apr 06, 2013 at 12:25 UTC
Re: regex error (backslashing)
by LanX (Canon) on Apr 06, 2013 at 15:30 UTC
    > It's OK when I type directly not using a string var.

    Different things!

    > $binpath="c:\\qa\\kontor\\bin"

    here you are backslashing to avoid string-interpolation within "doublequotes"

    > if( $ENV{PATH} !~ /c:\\qa\\kontor\\bin/i)

    here you are backslashing to avoid special escape \commands like \k

    So in your code you need 2 levels of escapes!

    $binpath="c:\\\\qa\\\\kontor\\\\bin";

    Do better combine 'singlequotes' and quotemeta \Q and you avoid any explicit backslashing.

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      Thanks to all. I use index function also solve this issue.
Re: regex error
by Anonymous Monk on Apr 06, 2013 at 10:54 UTC
Re: regex error
by igelkott (Curate) on Apr 06, 2013 at 15:11 UTC

    As other have pointed out, you should generally use the correct type of quoting.

    But, if you're just using hard-coded paths, you can skip the fancy quotes if you switch to unix-style paths. In other words, change the assignment to $binpath="c:/qa/kontor/bin";. As mentioned in this very old post, paths are converted automatically.

    Personally, I prefer this method so I can use the same script on PC and Linux. Well, at least for relative directories.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (13)
As of 2015-07-30 08:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (270 votes), past polls