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

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.

Replies are listed 'Best First'.
(tye)Re4: regexp searches over array slices
by tye (Sage) on Nov 12, 2001 at 02:59 UTC
    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!)

        Ah, then would evaluating a(n uncollapsed) superposition in a Boolean context generate a warning/error or would it cause both branches of the code to be (tentatively) run and the results to be indeterminate until something is done to collapse the (expanding) superposition? ;)

        This could add "logic programming" to Perl's bag of paradigms.

                - tye (but my friends call me "Tye")