Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: assigning to a hash via split

by japhy (Canon)
on Feb 19, 2001 at 06:49 UTC ( [id://59330]=note: print w/replies, xml ) Need Help??


in reply to assigning to a hash via split

Sure. Here's some short code for you:
while (<IN>) { chomp; my ($name) = /([^:]+)/; @{ $users{$name} }{ @fields } = split /:/; }
I basically create the hash reference and assign to it all at once.
update: down with temporary variables, up with one-liners.
chomp(@{$users{(/([^:]+)/)[0]}}{@fields} = split /:/) while <IN>;


japhy -- Perl and Regex Hacker

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://59330]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-19 19:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found