SPUG: When is a caret just a caret? And what about dollar?

Yitzchak Scott-Thoennes sthoenna at efn.org
Tue Oct 13 19:50:35 PDT 2009


On Sun, October 4, 2009 11:18 am, Joshua ben Jore wrote:
> \^ means the character '^'

Except when in a ^-delimited regex (and not interpolated), in which case
\^ means what ^ would otherwise have.

> ^ anywhere outside a character class and without //m on, means "match
> the start of the string" ^ with //m means "match the start of the string OR
> the start of any new line ^ as the first character in a character class
> inverts it ^ is part of a variable if the variable's name is something
> like $^W or ${^WARNING_BITS}
>
>
> \$ means the character '$'

Ditto re $-delimited regex.

> Regexps using ' as the quote are non-interpolating so $ still means
> the character '$' $ interpolates if the name matches:
> * normal names like $foo
> * capture variables like $1 or $314159265
> * names with leading control characters like $^X or ${^WARNING_BITS}
> * punctuation like $$
> * EXCEPT the variables $(, $|, $)
> $ that hasn't interpolated matches:
> * at the end of a string or before a \n at the end of a string if
> /m wasn't on
> * at all the middle newlines too if /m was on

You left out $foo[EXPR] and $foo{EXPR}, which may interpolate $foo
or may interpolate a hash or array element, depending on perl's guess.



More information about the spug-list mailing list