in reply to Re: How to ignore special characters in a variable ?
in thread How to ignore special characters in a variable ?

/Q.../E turns out to be better option than quotemeta. Just in case a beginner happens to read this node - remember - quotemeta modifies your string by adding "\" before special characters. If your string is a variable (like $string in above example), it becomes unusable.

Having fun with perl... :-)
  • Comment on Re^2: How to ignore special characters in a variable ?

Replies are listed 'Best First'.
Re^3: How to ignore special characters in a variable ?
by ikegami (Patriarch) on Feb 17, 2011 at 06:54 UTC

    \Q is quotemeta, so I don't see how it could be better.

    >perl -MO=Concise,-exec -e"qq{\Q$x}" 1 <0> enter 2 <;> nextstate(main 1 -e:1) v:{ 3 <#> gvsv[*x] s 4 <1> quotemeta[t2] sK/1 5 <@> stringify[t3] vK/1 6 <@> leave[1 ref] vKP/REFC -e syntax OK >perl -MO=Concise,-exec -e"quotemeta($x)" 1 <0> enter 2 <;> nextstate(main 1 -e:1) v:{ 3 <#> gvsv[*x] s 4 <1> quotemeta[t2] vK/1 5 <@> leave[1 ref] vKP/REFC -e syntax OK

    If you're just talking about how it looks in the code, ok.

Re^3: How to ignore special characters in a variable ?
by Anonymous Monk on Feb 17, 2011 at 05:24 UTC
    /Q /E isn't real syntax, but \Q \E is :)
      Oops.. my mistake