Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: To infinity and beyond: Embedding loops

by Skeeve (Parson)
on Jul 16, 2003 at 10:01 UTC ( [id://274750]=note: print w/replies, xml ) Need Help??


in reply to To infinity and beyond: Embedding loops

No infinite loop here. But is this really what you wanted?
use Data::Dumper; my @line= qw(a b c); my @angel=qw(1 2 b); for ( $i = 1 ; $i <= $#line ; $i++ ) { $k = $line[$i]; for ( $v = 1 ; $v <= $#angel ; $v++ ) { $j = $angel[$v]; if ( $k =~ m/($j)/i ) { push ( @a, $v ); } else { push ( @b, $v ); } } } print Dumper(\@a, \@b);
prints out:
$VAR1 = [ 2 ]; $VAR2 = [ 1, 1, 2 ];
BTW: Arrays start at 0 not at 1...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-19 06:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found