laziness, impatience, and hubris | |
PerlMonks |
Re: Stuck while learning about the hashby Arguile (Hermit) |
on Jun 08, 2001 at 11:40 UTC ( [id://86858]=note: print w/replies, xml ) | Need Help?? |
Hrmm... I might be really off here but wouldn't this construct be simpler? (pretty new to perl as well and not fully conversant with the intricacies of hashes)
I tried shift @_ then just @_ in the right side of the equation and learned again that it's evaluated all as one not left to right ;). Anyways, this way you get a data structure something like this:
Some examples on how to access it.
Printing out the structure (I've never used DATA::Dumper might it apply here?): tilly suggested the $h_ref for speed (less hash lookups per inner loop iteration), I'm declaring inside because I'm lazy and don't want to undef it after. It's output:
I didn't do any of the null checks, but that's pretty trivial to add. The \n in the split handles getting rid of the newline.. chomp may be better, I'm not sure. UpdateJust for fun I one lined the db to hash (not exactly efficient):
Update 2Oops, fixed up what Hofmator suggested... I swear I knew that about char classes I just didn't know split well enough and it sort of evolved that way as I worked through ;). Thanks.
In Section
Seekers of Perl Wisdom
|
|