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

Re: [perl #62056] Variable expansion in same regex as \N{} escaperesults in compilation error.

Thread Previous | Thread Next
July 17, 2009 01:23
Re: [perl #62056] Variable expansion in same regex as \N{} escaperesults in compilation error.
Message ID:
On Fri, Jul 17, 2009 at 10:02:32AM +0200, Rafael Garcia-Suarez wrote:
> 2009/7/16 Michael G Schwern <>:
> > Oddly enough, this is a case where a wild stretch of backwards compatibility
> > was broken.
> >
> > $ perl5.5.5 -wle 'print "\N{FOO}"'
> > N{FOO}
> >
> > $ perl5.6.1 -wle 'print "\N{FOO}"'
> > Constant(\N{...}) unknown: (possibly a missing "use charnames ...") at -e line
> > 1, within string
> > Execution of -e aborted due to compilation errors.
> >
> >
> > *ahem*
> Seriously, this is getting a bit tiresome. I don't know from where did
> originate this myth of P5P being opposed to any form of compatibility
> breakage, but it's a myth. A not a much flattering one. No dragons are
> slain in it. (or vampires)
> Did you notice that I recently added meaning for \N alone in regexes ?
> (the opposite of /\n/, for the record.) And what it someone was using
> it before ?

Well, in 5.10, \N without braces is actually an error:

  $ perl -wE '"" =~ /\N/'
  Missing braces on \N{} in regex; marked by <-- HERE in m/\N <-- HERE / at -e line 1.

as it is in 5.8.9 (and 5.6.2):

  $ /opt/perl/5.8.9/bin/perl -wle '"" =~ /\N/'
  Missing braces on \N{} at -e line 1, within pattern
  Execution of -e aborted due to compilation errors.

You'd have to go back to the 5.005 era (that is, the previous century)
to be able to have a '\N' in your regexp, and having it mean 'N'.

Also note the line in perlrebackslash:

   If the character following the backslash is a letter or a digit, then
   the sequence may be special; if so, it’s listed below. A few letters
   have not been used yet, and escaping them with a backslash is safe for
   now, but a future version of Perl may assign a special meaning to it.
   However, if you have warnings turned on, Perl will issue a warning if
   you use such a sequence.  [1].

So, it's not that we aren't documenting the fact that a letter preceeded
by a backslash may get a special meaning in a later version of Perl.

Perhaps the only people who may get bitten are the ones that have been
using 'N' as a regexp delimiter. 

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