Actually id say that that regex is not quite right. First of all this comes down to the defintion of a bareword, which isnt well defined from what ive read. But if we must discuss a regex for this purpose I would say it would be more like the following, but even then its not _entirely_ clear (the issue of v strings rears its head as well as a few other issues)
/^\s*([-A-Z_a-z][A-Z_a-z0-9]*|\d+)\s*/
(Im debating the \s* bit. Ive put it in becuase of Juerds comment below, but on reflection I dont actually think its necessary as the tokenizer would be remove the whitespace the surrounds the token preceeding the => digraph before the parser even saw the digraph.)
To be honest IMO there isnt an exact regex. The rules of the tokenizer are not representable by a regex as far as I know. (I could be wrong, it happens a lot. :-)
Some bizarre examples:
use strict;
use warnings;
local $\="\n"; local $,="\t";
print Zaxo => 'Juerd';
print Zax0 => Ju3rd => 'Foo';
print -abcde=>'foo';
print v9.100.101.109.101.114.112.104.113.9 => v65;
print 0 => 'foo';
print v48.65 => 'A0';
print 0x00 => 'foo'; #prints 0 not 0x00
# print 1a2b => 'foo'; #doesnt work, cant have alphas when the key sta
+rts with a digit (0x excepted)
# print 1a-2b => 'foo'; #doesnt do what you might think, evals to 0
Anyway, if you are interested in this , there is currently a discussion on p5p about the behaviour of => (started by Abigail-II) called
[perl #16010] v-strings left of a => don't get quoted.
It seems the issues of => and v strings are quite convoluted. :-)
Yves / DeMerphq
---
Software Engineering is Programming when you can't. -- E. W. Dijkstra (RIP)
|