in reply to Re^3: Question on Regex grouping
in thread Question on Regex grouping

People who dislike list slicing should avoid scripting languages, especially Perl. It's FALSE that you don't know whether there was a match with m//g because the created list is simply empty. Also, the GOATSE ( =()=) recreates the right context if that's an issue.

Take this code: $x = "a123b345c7865d87"; @L = ($x =~ /a-z/g)1,3; print "@L"; ## Prins b d @X = ($x =~ /#/g)[1,3]; print (defined(@X) ? "YES" : "NO";
It prints NO ... therefore, JavaFan, your assertions are FALSE and FALSE. TenThouPerlStudents

Replies are listed 'Best First'.
Re^5: Question on Regex grouping
by JavaFan (Canon) on Dec 22, 2010 at 11:44 UTC
    People who dislike list slicing should avoid scripting languages, especially Perl.
    Really? Just because I find list slices to avoid using $1 ugly? What else? People who don't like goto should avoid Perl? People who don't like m?? should avoid Perl? People who don't like code without warnings or strict?

    @X = ($x =~ /#/g)[1,3];
    Ain't working. Sure, for the given pattern, it works. Now, let's change the pattern a little, shall we:
    my $x = "1234"; my @X = ($x =~ /(#)?/)[1,3]; say scalar @X; # defined(@X) is deprecated say "Matched" if $x =~ /(#)?/; __END__ 0 Matched
    So, @X is empty, yet the pattern matches.
    It prints NO ... therefore, JavaFan, your assertions are FALSE and FALSE.
    When I say "it doesn't always work", a single example where it does work isn't a contradiction.

    Note also that Marshall wasn't doing it your way anyway, he put the list slice in scalar context.

      Even more "deprecated" is a "pattern" like (#)? where: a) There's no reason for the parens, and b) Where the pattern is ALWAYS true because you CANNOT FAIL to match zero instances of ANYTHING!!! I find your "refutation" bizarre!! Since when is asking if ANY type of variable "deprecated"???