Hey fellow perl monks! I recently discovered the use of the following loop control statements:
next last redo
However, I don't think I've quite understood their use. Say, I have a set I wish to iterate through. I'd like to iterate through a particular block while i = 0, and have the loop go through a 2nd block for values i >= 1.
#!/bin/perl use strict; use warnings; sub newl { print "\n"; print "\n"; } my @a; my @b; my $na; my $Na; $na = $#a; $Na = ( 0, 1..$na ); @a = ( /, /home, /var, /tmp, /var/tmp ); for my $i (@Na) { $b[$i] = `ls $a[$i]`; } for my $i (@Na) { my @c1 = split ("\n", $b[$i]); my $nc; my @Nc; $nc = $#c1; @Nc = ( 0, 1..$nc ); for my $w (@Nc) { print "$a[$i]$c1[$w]"; newl; } last if $i == 1; @c1 = split ("\n", $b[$i]); $nc = $#c1; @Nc = ( 0, 1..$nc ); for my $w (@Nc) { print "$a[$i]/$c1[$w]"; newl; } }
However, this goes through the first block at i=0 once, then goes through the second block at i=0, and stops again right before i=1. What is the best way for me to accomplish me going through the first block in the loop for i=0, and iterate through the second block for all values of i>=1 ?

In reply to Loop Control by slugman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.