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"; }