Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: returning to the outer loop

by Marshall (Canon)
on Sep 20, 2018 at 21:25 UTC ( [id://1222754]=note: print w/replies, xml ) Need Help??


in reply to returning to the outer loop

I am unsure about what you are trying to accomplish. I of course can't run your code as an example. I just didn't understand it.

UPDATE: OMG, I got along the wrong track because of your original code which appeared to have several nested loops. The right Perl thing to "exit a single loop" is: last. You need a Label to jump a couple of levels up! But not here! Sorry about the confusion!

#!/usr/bin/perl use warnings; use strict; my @x = ( ['aaaaa', 'bbbbb', 'ccccc', 'ddddd',], ['eeeee', 'fffff', 'ggggg', 'hhhhh',], ['iiiii', 'jjjjj', 'kkkkk', 'lllll',], ); #@x is a 2D array, an AoA (Array of Array) OUTER: for my $row_ref (@x) { for my $element (@$row_ref) { # call exit(1) to competely stop! # with error code 1 if ($element eq 'ggggg') { print "stop seen\n"; next OUTER; #last; would work here } else { print "$element\n"; } } } __END__ Prints: aaaaa bbbbb ccccc ddddd eeeee fffff stop seen iiiii jjjjj kkkkk lllll
See also Perl "redo"....

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-19 04:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found