ukhas jean wrote:
> whts the use of \Q \E in a regex pattern? I did a google and found the
> below meaning (which is some tech mumbo-jumbo ... i cldnt understand).
>
> \E end case modification
> \Q quote non-word characters till \E
> I also read somewhere on the net abt some "auto-evaluation" that these
> options do ...
> when do i make use of these two options??
\Q ... \E is in essence the same as using quotemeta in a vrbl. Since I
have my man pages in one file a search easily turns up more info - here's
much of it :
quotemeta EXPR
quotemeta
Returns the value of EXPR with all non-"word" characters
backslashed. (That is, all characters not matching "/[A-Za-z_0-9]/"
will be preceded by a backslash in the returned string, regardless
of any locale settings.) This is the internal function implementing
the "\Q" escape in double-quoted strings.
Also:
You cannot include a literal "$" or "@" within a "\Q" sequence. An unescaped
"$" or "@" interpolates the corresponding variable, while escaping will
cause the literal string "\$" to be inserted. You'll need to write something
like "m/[EMAIL PROTECTED]/".
More:
"\Q", "\U", "\u", "\L", "\l" (possibly paired with "\E") are
converted to corresponding Perl constructs. Thus, "$foo\Qbaz$bar" is
converted to "$foo . (quotemeta("baz" . $bar))" internally. The
other combinations are replaced with appropriate expansions.
Let it be stressed that *whatever falls between "\Q" and "\E"* is
interpolated in the usual way. Something like "\Q\\E" has no "\E"
inside. instead, it has "\Q", "\\", and "E", so the result is the
same as for "\\\\E". As a general rule, backslashes between "\Q" and
"\E" may lead to counterintuitive results. So, "\Q\t\E" is converted
to "quotemeta("\t")", which is the same as "\\\t" (since TAB is not
alphanumeric). Note also that:
$str = '\t';
return "\Q$str";
may be closer to the conjectural *intention* of the writer of
"\Q\t\E".
Interpolated scalars and arrays are converted internally to the
"join" and "." catenation operations. Thus, "$foo XXX '@arr'"
becomes:
$foo . " XXX '" . (join $", @arr) . "'";
All operations above are performed simultaneously, left to right.
Because the result of "\Q STRING \E" has all metacharacters quoted,
there is no way to insert a literal "$" or "@" inside a "\Q\E" pair.
If protected by "\", "$" will be quoted to became "\\\$"; if not, it
is interpreted as the start of an interpolated scalar.
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs