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

Well, Perl 6 will let you do:
if (@array[3,4] ^=~ /\S/) { ... }
so, in Perl 6, will that mean "and" or "or"?

Neither. It's exactly the same as: if (@array[3] =~ /\S/, @array[4] =~ /\S/) { ... }

which is true if @array[4] contains any non-whitespace.

That is, I recall ^=~ being able to work over a list, but what will if do with the resulting list?

Just what a Perl 5 if does with it.

In other words, does it become this (a grep-ish map)?

No, I don't believe so.

BTW, what you're looking for is: if (any(@array[3,4]) =~ /\S/) {...} or: if (all(@array[3,4]) =~ /\S/) {...} both of which (I'm very hopeful) will be standard in Perl 6.

Replies are listed 'Best First'.
Re: Re: (tye)Re: regexp searches over array slices
by japhy (Canon) on Nov 09, 2001 at 19:49 UTC
    Ah, ok. I learned something new. And your dang-blasted "in constant time!" functions might find their way to the Perl 6 core? I have some nasty words for you, but I said them all at the same time and they came out jumbled. You're lucky. ;)

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

      In constant time?

      I think not.

      Not even in a parallel universe are they constant time.

      Now if you had an unlimited supply of parallel universes, that might be different...

      But in the meantime I am sticking with my comment that Quantum::Superpositions is where Moore meets Murphy.

(tye)Re3: regexp searches over array slices
by tye (Sage) on Nov 09, 2001 at 20:36 UTC

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