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

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")

Replies are listed 'Best First'.
Re: (tye)Re4: regexp searches over array slices
by TheDamian (Vicar) on Nov 15, 2001 at 01:09 UTC
    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")
        ...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? ;)

        Err...neither.

        In a boolean context, a disjunctive superposition evaluates to true if any of its eigenstates is true, whilst a conjunctive superposition evaluates to true only if all of its eigenstates are true.

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

        Sssssssssshhhhhhhhhhhh!!!!!!! How the heck am I supposed to sneak these new paradigms in if you keep warning everybody beforehand??? ;-)

        But, yes, that's the general idea. It would be rather nice to be able to code an n-ary max subroutine declaratively, like so:

        sub max (*@values) { any @values >= all @values }
        Especially since that version is vastly more amenable to internal parallelization.