I *had* a problem that I solved myself, namely that the hashrefs in @list had been replaced by scalars after the second for loop in the code below. I do perl for 6 years now but I still underestimate the globalness of $_ sometimes. My question is, is my intuition so far of the line, namely that $_ feels to me more block scoped, that I don't expect the "for @list" to replace the contents of @list because they are assigned to $_? Or did I forget to read some important documentation that should be read in the beginning. I did read almost the complete Camel Book (version 2).
Here's a simplified version of the code. The work_ sub was far away in a module and difficult to find then.
Hoping for some enlightenment on the nature of $_ ...
my @list = ( { a => 1 }, { a => 15 } );
# here the values of a in the hashrefs are changed, ok!
work_( $_ ) for @list;
print "_=".(ref $_ ? "r.$_->{a}" : $_) . "\n" for @list;
# but here the hashrefs in @list are replaced by scalars,
# namely the result of the work_() call.
work_( $_, 1 ) for @list;
print "_=".(ref $_ ? "r.$_->{a}" : $_) . "\n" for @list;
sub work_ {
my ($obj, $act) = @_;
$obj->{a}++;
$_ = $obj->{a} if $act;
}