Peter Rabbitson wrote:
I am getting this:
[EMAIL PROTECTED]:~$ perl -e "'123456-123456' =~ /^ (\d{2}){3} (?: - (\d{2}){3} )?
$/x ? print 'yep' : print 'nope';"
Panic opt close in regex m/^ (\d{2}){3} (?: - (\d{2}){3} )? $/ at -e line 1.
It looks like the regular expression engine does not like the expression
(?:-(\d{2}){3})? but either (?:-(?:\d{2}){3})? or (-(\d{2}){3})? will work.
Google does not turn much if anything about this error...
Neither does perldiag.pod, which is where you should search first for
warning
and error messages.
Why is this
happening? If I remove ?: everything goes well but it defies the idea of the
exercise to get an optional 3 pair set of digits parsed as $4 $5 $6 in the
same pass as $1 $2 $3.
Your expression only has two sets of capturing parentheses so only $1 and $2
will contain any useful data. If you want to populate $1 through $6 then this
will work:
/^ (\d\d) (\d\d) (\d\d) (?: - (\d\d) (\d\d) (\d\d) )? $/x
BTW, instead of typing 'print' twice in the expression:
'string' =~ /pattern/ ? print 'yep' : print 'nope';
It is usually written like this:
print 'string' =~ /pattern/ ? 'yep' : 'nope';
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>