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

Joshua ben Jore twists at gmail.com
Tue Dec 8 11:41:38 PST 2009


On Wed, Oct 14, 2009 at 6:58 AM, Michael R. Wolf <michaelrwolf at att.net> wrote:
>
> On Oct 13, 2009, at 7:50 PM, Yitzchak Scott-Thoennes wrote:
>
>> 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.
>
> Guess?  You mean it's non-deterministic?  Oh, the horror!  :-)

It's deterministic but probably difficult to prove correct. The code
is S_intuit_more in toke.c:

  * Returns TRUE if there's more to the expression (e.g., a subscript),
  * FALSE otherwise.

It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/

* ->[ and ->{ return TRUE
* { and [ outside a pattern are always subscripts, so return TRUE
* if we're outside a pattern and it's not { or [, then return FALSE
* if we're in a pattern and the first char is a {
* {4,5} (any digits around the comma) returns FALSE
* if we're in a pattern and the first char is a [
*   [] returns FALSE
*   [SOMETHING] has a funky algorithm to decide whether it's a
character class or not.  It has to deal with things like /$foo[-3]/
and /$foo[$bar]/ as well as /$foo[$\d]+
* anything else returns TRUE

/* This is the one truly awful dwimmer necessary to conflate C and sed. */

Josh


More information about the spug-list mailing list