http://qs321.pair.com?node_id=558529


in reply to hash from sub directly into foreach loop

First of all, the syntax in the sub is incorrect:
%s{'a'} = 10 ; %s{'b'} = 20 ; %s{'c'} = 30 ;
should be
$s{'a'} = 10 ; $s{'b'} = 20 ; $s{'c'} = 30 ;
anyway, the following change will work for you:
#!/usr/bin/perl use strict ; use warnings ; foreach ( keys %{&testa} ) { print "key is $_\n" ; } sub testa { my $s = () ; $s->{'a'} = 10 ; $s->{'b'} = 20 ; $s->{'c'} = 30 ; return $s ; }
hope this helps,
davidj