I use map a fair bit in instances like this:
In that very limited scope, I feel it's fairly clear what $_ is. Another example:$sth_insert->execute ( map { $fields{ $_ } } qw/ITEMNO OPTFIELD AUDTUSER AUDTORG VALUE TYPE LENGTH DECIMALS ALLOWNULL VALIDATE SWSET/ ) or $log->logdie ( "Error with $insert_cmd: " . $sth_insert->errstr );
(And I'm sure there's a clever way to do that in one statement, and maybe someone smarter than me will suggest it.) Finally, this is also handy:my @good = grep { $_->{'result'} != 0 } @list; my @bad = grep { $_->{'result'} == 0 } @list;
That's about the largest scope that I use $_ for. After that, I tend to use $k (for key) when I'm iterating over a hash:for ( 0..2 ) { defined $item_image_url->[ $_ ] or last; $new_values{ "ITEMIMAGEUR$endings[ $_ ]" } = $item_image_url->[ $_ ] // ''; }
I get that having $_ appear in code can be a little odd when the scope is anything larger than Quite Small -- it stops you from grokking the code and makes you go back and figure out what the heck the value is, and where it came from.foreach my $k ( keys %DBhandles ) { $DBhandles{ $k }{ sth }->finish; $DBhandles{ $k }{ dbh }->disconnect; }
In reply to Re^4: 5.40 released
by talexb
in thread 5.40 released
by hippo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |