in reply to Re^3: array or hash reference
in thread array or hash reference

Actually the data in @jobs would be the same at that moment. Although %hash could be accessed/manipulated separately;

update  as answer to davido's post here below:
That's actuallay what I meant: pushing the hashref onto the array (as in snippet 1) lets you change the "data" of the array by changing the hash referenced.
While pushing the hash itself onto the array (as in snippet 2) takes a copy of the content of the hash and is afterwards independant of the hash.

pelagic

Replies are listed 'Best First'.
Re^5: array or hash reference
by davido (Cardinal) on Aug 11, 2004 at 07:45 UTC

    True, but you must beware the subtile bugs that could introduce if you're not careful. Consider the difference between the two following snippets:

    # snippet 1: use Data::Dumper; my @array; my %hash = ( 'one' => 1, 'two' => 2 ); foreach ( 1 .. 100 ) { push @array, \%hash; $hash{'one'}++; } print Dumper \@array; # snippet 2: use Data::Dumper; my %hash = ( 'one' => 1, 'two' => 2 ); my @array; foreach ( 1 .. 100 ) { push @array, { %hash }; $hash{'one'}++; } print Dumper \@array;

    Dave