in reply to Calculating variable {n} in regex match
use warnings; use strict; my $foo = shift || 12; my $i = 2; print "Is \`$foo' a two-digit number ... "; #my $rc = ($foo =~ /^[0-9]{($i + 1)}$/) ? 'yes' : 'no'; my $rc = ($foo =~ /^[0-9]{$i}$/) ? 'yes' : 'no'; #my $rc = ($foo =~ /^[0-9]{2}$/) ? 'yes' : 'no'; print $rc,"\n"; __END__ Is `12' a two-digit number ... yes
Add re to your code to see what is happening under the hood:
use re 'debug';
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Calculating variable {n} in regex match
by atreyu (Sexton) on Jun 05, 2012 at 17:56 UTC |