in reply to Re^2: 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^4: Question on Regex grouping
by TenThouPerlStudents (Initiate) on Dec 22, 2010 at 03:42 UTC

    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
      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"???
Re^4: Question on Regex grouping
by TenThouPerlStudents (Initiate) on Dec 22, 2010 at 03:50 UTC

    Sorry about the format but ... why does one need to use HTML tags to format one's own post???? It's my first post. I guess I'm used to sites more intelligently designed that format as written in the window.

    Nonetheless, the points I made are compelling. JavaFan's assertions are absolutely false. List slicing of //g, if it creates no list, makes the list variable undefined

    I'd also like to add that Perl nitpickers like to get all hot and bothered about lists vs. arrays yet the goatse is the one stop shop that enables //g to be added if one is COUNTING matches.

    I've largely avoided this site because as a lurker I've noticed that the "priests" and above are more interested in obscurantism and showing off than in helping newbies correctly and getting jobs done simply. TMTOWTDI is VASTLY abused here.