in reply to regexp searches over array slices

Well, Perl 6 will let you do:
if (@array[3,4] ^=~ /\S/) { ... }
but in the meantime, grep() is the tool for you:
if (grep /\S/, @array[3,4]) { ... }

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

Replies are listed 'Best First'.
(tye)Re: regexp searches over array slices
by tye (Sage) on Nov 09, 2001 at 03:42 UTC

    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")
      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:??;

        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")
      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:??;