
japhy
Enthusiast
/ Moderator
Jan 26, 2000, 3:38 PM
Post #4 of 5
(1966 views)
|
If you want to use hash references, that is perfectly fine. However, this is one case where you can learn the magic of typeglobs. <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> *hash = foo(); bar(*hash); # or bar(\%hash) sub foo { my %hash = ( ... ); return \%hash; } sub bar { local *hash = $_[0]; # do stuff with %hash normally } </pre><HR></BLOCKQUOTE> Globs stop you from having to EXPLICITLY use references, or from having to COPY large data structures. However, since this isn't a copy, it is actually an alias: <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> $a = "foo"; *b = *a; $b = "bar"; print $a; # bar $a = "foo"; @a = ("this","that"); *b = \@a; $b = "bar"; push @b, "those"; print $a; # "foo" print "@a"; # "this that those" </pre><HR></BLOCKQUOTE> Typeglobs are discussed somewhat in perlref, and in more detail in perldata.
|