Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: variable quantifiers?

by AnomalousMonk (Abbot)
on Jan 06, 2014 at 21:57 UTC ( #1069588=note: print w/ replies, xml ) Need Help??


in reply to variable quantifiers?

>perl -wMstrict -le "my $c = 'A'; my $min = 3; ;; my $s = 'uuAvvAAwwAAAxxAAAAyy'; ;; printf qq{'$1' } while $s =~ m{ ([[:lower:]] (?:$c){$min,} [[:lower:] +]) }xmsg; " 'wAAAx' 'xAAAAy'

Update: The quantified sub-pattern in  (?:$c){$min,} needs to be enclosed in a group (non-capturing or capturing) because otherwise  $c{$min,} looks to Perl too much like the interpolation of a scalar hash element from the  %c hash.

Further Update: Interesting. I was unaware of the  \ (backslash) disambiguation pointed out below.

Further Further Update: Or maybe not so interesting, since the regex doesn't actually seem to match anything:

>perl -wMstrict -le "my $c = 'A'; my $min = 3; $_ = 'AAAAAA'; print 'match' if /($c\{$min,})/; print qq{'$1'}; " Use of uninitialized value $1 in concatenation (.) or string at -e lin +e 1. ''

Yet Another Update: It is also possible to use a constant, but it's kinda messy. A Readonly scalar might do a better job for you.

>perl -wMstrict -le "use constant MIN => 3; my $c = 'A'; ;; my $s = 'uuAvvAAwwAAAxxAAAAyy'; ;; printf qq{'$1' } while $s =~ m{ ([[:lower:]] (?:$c){${ \MIN },} [[:lower:]]) }xmsg; " 'wAAAx' 'xAAAAy'


Comment on Re: variable quantifiers?
Select or Download Code
Replies are listed 'Best First'.
Re^2: variable quantifiers?
by Anonymous Monk on Jan 06, 2014 at 22:04 UTC
    $ perl -e " use re 'debug'; $c='a'; $min=3; m/$c\{$min,}/; " Compiling REx "a\{3,}" Final program: 1: EXACT <a{3,}> (4) 4: END (0) anchored "a{3,}" at 0 (checking anchored isall) minlen 5 Freeing REx: "a\{3,}"

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1069588]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (13)
As of 2015-07-28 09:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls