in reply to Foreach & scalar ref: break of way that it is suposed to work!

Try this:

my %hash = ( key => 'value'); my $k_ref = \$hash{key} ; *{'main::val'} = $k_ref ; ## To avoid $$k_ref print "val: <$val>\n" ; print "key: <$hash{key}>\n" ; { local( $val )= 'test' ; print "val: <$val>\n" ; print "key: <$hash{key}>\n" ; }
and note that it produces
val: <value> key: <value> val: <test> key: <value>
and you might see the light.

foreach does an implicit local which does a rough equivalent of

my $saved= *main::val{SCALAR}; *main::val= do { my $new; \$new }; ... *main::val= $saved;
That is, it copies off and saves the reference to the variable rather than the value contained in the variable.

                - tye