in reply to Re: regexp searches over array slices
in thread regexp searches over array slices

Um,

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

That is, I recall ^=~ being able to work over a list, but what will if do with the resulting list? Will /\S/ be given a list context so that it returns an empty list upon failure so the final list is empty if and only if both matches failed?

In other words, does it become this? if(  map {/\S/} @array[3,4]  ) { (which has the same effect as the grep version but for slightly different reasons).

So, I think I've answered my own question but I'll post this anyway as I think some might find it interesting.

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

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

      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.

      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.

Re: (tye)Re: regexp searches over array slices
by japhy (Canon) on Nov 09, 2001 at 03:49 UTC
    I believe it acts like grep() here, but I could be wrong. Perhaps we should tap TheDamian.

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