develooper Front page | perl.perl5.porters | Postings from August 2009

Re: [perl #68804] underscore regex delimiters

Thread Previous | Thread Next
August 27, 2009 01:33
Re: [perl #68804] underscore regex delimiters
Message ID: (via RT) wrote:
>$ perl -p -e 's_/32__;'

The underscore is not perceived as a delimiter there, but as part of
an identifier.  Observe how it was parsed:

$ perl -MO=Deparse -e 's#/32##;' 
-e syntax OK
$ perl -MO=Deparse -e 's_/32__;' 
's_' / 32;
-e syntax OK

Other clues are available if you turn on warnings:

$ perl -wce 's_/32__;'           
Misplaced _ in number at -e line 1.
Misplaced _ in number at -e line 1.
Useless use of division (/) in void context at -e line 1.
-e syntax OK

And if the substitution had contained other text then it would have
blown up earlier:

$ perl -wce 's_\\__;' 
Backslash found where operator expected at -e line 1, near "s_\"
syntax error at -e line 1, near "s_\"
-e had compilation errors.

I believe the documentation is at fault.  perlop(1) says:

    Any non-alphanumeric, non-whitespace delimiter may replace the

Underscore is not alphanumeric or whitespace, but is evidently
being treated the same way that an alphanumeric character would be.
The prohibition is really on identifier characters, not alphanumerics.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About