FryingFinn has asked for the wisdom of the Perl Monks concerning the following question:
Can one (or more to the point, I) use a variable as a quantifier value in a regex ? As illustrated in below...
#!/usr/bin/perl -w use constant minUC => 3; my $min = 3; my $test = "AAAAAA"; my @chars = (split //, $test); my $Rep = 0; foreach my $c ( @chars) { $Rep++ if ($test =~ /$c{3,}?/) ; # this works # $Rep++ if ($test =~ /$c{$min,}?/) ; # no work; # $Rep++ if ($test =~ /$c{minUC,}?/) ; #nor does using a named cons +tant }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: variable quantifiers?
by AnomalousMonk (Archbishop) on Jan 06, 2014 at 21:57 UTC | |
by Anonymous Monk on Jan 06, 2014 at 22:04 UTC | |
|
Re: variable quantifiers? (TIMTOWTDI)
by LanX (Saint) on Jan 07, 2014 at 01:23 UTC | |
|
Re: variable quantifiers?
by lidden (Curate) on Jan 07, 2014 at 06:32 UTC | |
by LanX (Saint) on Jan 07, 2014 at 08:58 UTC | |
by Anonymous Monk on Jan 07, 2014 at 07:02 UTC |