SPUG: Reference to a hash
James Moore
james at banshee.com
Fri Mar 22 11:35:31 CST 2002
I find that when I'm using the kind of construction Jim describes it's
because I'm planning on doing some processing to the hash after creating
it:
while (my $line = <STDIN>) {
%hash = my_func($line);
...
$hash{foo} = $bar;
$things{$key} = \%hash;
}
Rather than the anonymous hash construction using {}, I usually make the
hash a 'my' variable:
while (my $line = <STDIN>) {
my %hash = my_func($line);
...
$hash{foo} = $bar;
$things{$key} = \%hash;
}
Doing it this way I find is slightly clearer than using
$things{$key}{foo} = $bar, plus it involves slightly less typing. It's
really only an issue for slightly more complex operations.
I suspect that you get to this point naturally if you're using 'use
strict.'
Strict is your friend - don't attempt to write non-trivial perl code
without it.
------------------------------------------------------------
James M. Moore
james at banshee.com
Banshee Software: Web software development
Open Source / .NET / Embedded
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org
More information about the spug-list
mailing list