http://qs1969.pair.com?node_id=46285


in reply to Re: question mark in there
in thread question mark in there

That's not necessarily a bad way to do it, but everyone should be aware that if there are any metacharacters in $b and \E precedes them, the metacharacters will be parsed as metacharcters.
IOW, if $b == "???\E?", the fourth '?' will be not be matched literally.

The only real advantage to punk music is that nobody can whistle it.

Replies are listed 'Best First'.
Re: Re: Re: question mark in there
by chipmunk (Parson) on Dec 12, 2000 at 22:23 UTC
    I was skeptical about this warning, and a simple experiment shows that it is not accurate:
    DB<1> $x = '???\E???' DB<2> p "\Q$x" \?\?\?\\E\?\?\? DB<3>
    A \Q cannot be ended by a \E in an interpolated string. And, using B::Deparse's -q option in 5.6, we can see why:
    ~> perl -MO=Deparse,-q -e '$x = q{?\E?}; $y = "a\Q$x\Eb"; print "$y\n" +' $x = '?\\E?'; $y = quotemeta $x; print $y . "\n"; -e syntax OK
    This shows that \Q\E inside a double-quoted string is actually compiled as concatenation and quotemeta. The value of $x at runtime won't change the scope of the quotemeta().