Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Do the changes to the regular expression syntax seem woefully under-publicized here?

    Was:    $str =~ m/^\d{2,5}\s/i
    Now:    $str ~~ m:P5:i/^\d{2,5}\s/ # :P5 indicates Perl5-compatibile regex syntax

    Was:    $str =~ s/(a)/$1/e;
    Now:    $str ~~ s:P5/(a)/{$0}/;    # $1 is now $0
I actually find the change from $1 to $0 particularly disturbing, since that is well standardized and group 0 normally refers to the whole matched pattern (though Perl had to give it a different name and for some reason has always discouraged its use).

They also provide no information here on the non-"Perl5-compatible" regexes, but they do talk about it a bit in Specification 5: http://design.perl6.org/S05.html There are some really interesting changes there, and we'll see what comes of this -- PCRE has become a de-facto standard, so I'm curious to see what happens as Perl moves away from "PCRE-compatible" syntax.



It seems "disturbing" is the good word here, as the kind of changes in the semantics or notation between Perl 5 and Perl 6 almost guarantees that most potential users would have to decide if they are going to reject using one or another: The need to "read differently" on the distant look similar code demands too much from the people who'd just like to "get the job done."

What's that $1? Well it's the first match if it's Perl 5 but it's a second match if it's Perl 6. But don't worry, the other things in expressions also have sometimes other meanings.


don't use $1, use named captures or list assignment. qr/\$\d+/ is a oneliner thing or a code smell.


It's not a smell if you are doing an asston of text munging. Rather than write one ginormo regex I prefer a sequence of short actions. It's easier to debug and reason with.


Use named captures or list assignment. $1 $2 etc are already a code smell in Perl 5. Action-at-a-distance is the enemy.


That's needlessly verbose if I am descoping $1 within a line or two. I agree one must be careful.


I remember reading about the Perl 6 reinvention of regular expressions in 2009 and being really excited about it, as the syntax changes seemed really grounded in the actual experience of using regular expressions (such as my own).




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: