Likewise, you can pass a reference into a subroutine and use it withou +t dereferencing: %units = (miles => 6, stones => 11); fillerup( \%units ); # Pass in a reference print $units{quarts}; # Prints 4 sub fillerup { local *hashsym = shift; # Assign \%units to the typeglob $hashsym{quarts} = 4; # Affects %units; no dereferencing neede +d! } These are tricky ways to pass around references cheaply when you don't + want to have to explicitly dereference them. Note that both techniqu +es only work with package variables; they would not have worked had w +e declared %units with my.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Error in camel book 3
by trantor (Chaplain) on Oct 03, 2001 at 16:08 UTC | |
|
Re: Error in camel book 3
by pixel (Scribe) on Oct 03, 2001 at 14:23 UTC | |
|
Re: Error in camel book 3
by petral (Curate) on Oct 03, 2001 at 22:17 UTC | |
|
Re: Error in camel book 3
by Cine (Friar) on Oct 04, 2001 at 13:23 UTC |