Why is my Perl not working on that command?

$ perl -e 'exit(10) if "aaa"=~/a{,2}/;'
Unescaped left brace in regex is illegal here in regex; marked by <-- HERE in m/a{ <-- HERE ,2}/ at -e line 1.
$

But this works:
$ perl -e 'exit(10) if "aaa"=~/a{0,2}/;'
$

$ echo $?
10
$

It sure surprised me that the first one did not work for me.

Do I need to upgrade my Perl?
$ perl -v

This is perl 5, version 30, subversion 0 (v5.30.0) built for x86_64-linux
(with 1 registered patch, see perl -V for more detail)
snip
$

I just went through my Perl documentation and none of
it allows {,2}.  Learning Perl Second Edition (July 1997)
says:
"If you leave off the second number, as in /x{5,}/, it means "that many or more" (five or more in this case), and if you leave off the comma, as in /x{5}/, it means "exactly this many" (five x's).
To get five or less x's, you must put the zero in, as in /x{0,5}/."


Mike


On 1/22/24 06:23, Jorge Almeida wrote:
Please help me to understand this:
$ perl -e 'exit(10) if "aaa"=~/a{,2}/;'
$ echo $?
$ 10

Thanks

Jorge Almeida

Reply via email to