Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

while loop with logical or

by perlkiller (Acolyte)
on Dec 19, 2011 at 22:14 UTC ( [id://944312]=perlquestion: print w/replies, xml ) Need Help??

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

Hello, I tried to combine the inner while loops into one loop but it doesn't work. It goes into infinite loop

#!/usr/bin/perl use strict; use warnings; my $d = qr/\d/; #number my $a = qr/[a-c]+/; #alpha while (<DATA>) { #while ( /($a)/g ) { # print "$1\n"; #} while ( /($a)/g || /($d)/g ) { #<----won't work #while ( /($d)/g ) { print "$1\n"; } } __DATA__ 1 a 2 aa 3 aaa 4 b 5 bb 6 bbb 7 c 8 cc 9 ccc

Original content restored above by GrandFather

nevermind I fixed it already

while ( /($a|$d)/g ) {

Replies are listed 'Best First'.
Re: while loop with logical or
by Util (Priest) on Dec 19, 2011 at 22:29 UTC
    # Interleaved order while ( /($a|$d)/g ) { print "$1\n"; }
    or
    # Original order. Note that $1 is now $_. for ( /($a)/g, /($d)/g ) { print "$_\n"; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-20 01:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found