Orton, Yves writes: > > (There's equivalent reasoning behind the existence of > > push_attribute().) > > But in this case its unwarranted. > > my $foo=undef; > push @$foo,"Bar"; > print "@$foo\n"; But if the undef is returned from a function, the autovivification only happens to the local copy, not the version used by the function: my %hash; sub a { return $hash{foo} } my $foo = a(); push @$foo, "Bar"; print "@$foo\n"; print "@{$hash{foo}}\n"; Compare with: my %hash; push @{$hash{foo}}, 'Hello'; sub a { return $hash{foo} } my $foo = a(); push @$foo, "Bar"; print "@$foo\n"; print "@{$hash{foo}}\n"; Hence the need for a method that always results in pushing on to the array reference stored in the hash, regardless of whether it already has any values in there. SmylersThread Previous | Thread Next