in reply to Better way to add refs to an array or hash?
There's always MTOWTDI ... You've just managed to find one of the more extreme methods (without going into function calls). As cog said, you can just assign $tokens{$id} = $href. But the other way (my preference) would be:
Of course, there are a bazillion ways to get the text between the first and second dot, but that's not the question here, so I'm leaving well enough alone. The only real change to that line was the removal of the arrow notation since I changed from using a hashref to using just a plain hash. Each time through the loop, we'll get a new hash, and the %tokens hash will have references to no-longer-named hashes that have otherwise fallen out of scope. Either solution (cog's or this one) should be faster than yours (no copying), but otherwise there's probably no significant difference between them (likely the same speed). The only difference is the sigils.while (<$fd>) { my %href = map { split '=', $_, 2 } split ';'; my $id = (split '\.', $href{TOKEN})[1]; $tokens{$id} = \%href; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Better way to add refs to an array or hash?
by Argel (Prior) on Mar 25, 2005 at 01:02 UTC |