[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Loop question



My apologies.  In the examples I gave (below), I misplaced a line of code [A
good example of why you should always test your code to make sure it works
before submitting it as a suggestion :) ]  The following changes fix the
error:

> foreach $line(@whole) {
> last if ++$counter == 8;
> $line =~ s/\n//g;
> print "$line\n";
> }

should be

foreach $line(@whole) {
    $line =~ s/\n//g;
    print "$line\n";
    last if ++$counter == 8;
}

And

> for(@whole) {
> # $_ is locally set to the current line ($line in above sample)
> last if ++$counter == 8;
> s/\n//g;
> print "$_\n";
> }

should read

for(@whole) {
    chomp;
    print "$_\n";
    last if ++$counter == 8;
}

Again, sorry for the confusion.

David


# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org