[Omaha.pm] for loop quickie

Andy Lester andy at petdance.com
Mon May 22 14:14:24 PDT 2006


>
> after:
>
>    for (@row) {
>       s/[^ -~]//g;
>       s/\|/:/g;
>    }

Beautiful.  Getting out of the C mindset of keeping a loop index is  
one of the big steps into Perl mastery.

Note that in this example, there's an implicit $_ being used as the  
loop variable.  You can also make it explicit:

for my $entry (@row) {
     $entry =~ s/...../;
}

In this case, although it looks like $entry is a temporary variable,  
and that changes to $entry will get thrown away, that's not the  
case.  $entry is an alias to the iterated variable.

xoa


--
Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance





More information about the Omaha-pm mailing list