Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Have to abruptly return in a regex

by Anonymous Monk
on Jan 10, 2022 at 15:34 UTC ( [id://11140326]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

How can we do abort then return on true condition in a regex as
$n=0;$m=2; sub l{ 'oXoXoXoX' =~ /(?:.X(?{return "Yes n=$n" if ++$n==$m}))*/ } print &l; 1 fails ?

Please guide to the correct one

Replies are listed 'Best First'.
Re: Have to abruptly return in a regex
by LanX (Saint) on Jan 10, 2022 at 16:17 UTC
    this

    > "oXoXoXoX" =~ /(?:.X(?{return "Yes n=$n" if ++$n==$m}))*/

    looks like a very complicated way of trying

    DB<44> sub func { my ($m)=@_; return "Yes n=$m" if 'oXoXoXoX' =~ /(? +:.X){$m}/ } DB<45> p func(0) Yes n=0 DB<46> p func(2) Yes n=2 DB<47> p func(4) Yes n=4 DB<48> p func(5) DB<49>

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Re: Have to abruptly return in a regex
by LanX (Saint) on Jan 10, 2022 at 16:05 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11140326]
Approved by LanX
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found