Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
>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'

In reply to Re: variable quantifiers? by AnomalousMonk
in thread variable quantifiers? by FryingFinn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-24 02:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found