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.next last redo
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 ?#!/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; } }
In reply to Loop Control by slugman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |