in reply to Re: (tye)Re: regexp searches over array slices
in thread regexp searches over array slices

Just so everyone is clear... This means that (scalar) context will be preserved by ^=~ (and other ^ constructs), correct?

        - tye (but my friends call me "Tye")
  • Comment on (tye)Re3: regexp searches over array slices

Replies are listed 'Best First'.
Re: (tye)Re3: regexp searches over array slices
by TheDamian (Vicar) on Nov 11, 2001 at 02:20 UTC
    This means that (scalar) context will be preserved by ^=~ (and other ^ constructs), correct?

    It means that hyperoperators will distribute their own context (whatever it is) to each component of the operation, and then aggregate the results into a list.

    For example:

    $foo = @bar ^=~ /baz/; # each @bar[$i] =~ /baz in scalar context @foo = @bar ^=~ /baz/; # each @bar[$i] =~ /baz in list context

    Hmmmm. That brings up an interesting point though. If the results were aggregated into an array rather than a list, then japhy's greppish interpretation of if (@var ^=~ /baz/) {...} might well be correct, after all.

    I'm going to have to thrash this out with Larry. Thanks for raising the issue.

      If the results were aggregated into an array rather than a list, then japhy's greppish interpretation of if (@var ^=~ /baz/) {...} might well be correct, after all.

      Except that, by giving a scalar context, the resulting array would be something like (undef,undef) which would still be "true".

              - tye (but my friends call me "Tye")
        Good point.

        That probably means that you need to use an explicit superposition to get the effect you want:

        if (any(@var ^=~ /baz/)) {...}

        or:

        if (any(@var) =~ /baz/) {...}

        (Though I will hint darkly at other possibilities that the Perl 6 design team are tossing about -- such as unification of hyperoperators and superpositions!)