Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Hashes with multiple values?

by amarquis (Curate)
on Mar 31, 2008 at 02:42 UTC ( [id://677433]=note: print w/replies, xml ) Need Help??


in reply to Hashes with multiple values?

There are several things that will keep your code from compiling, but I take it you want big picture comments/criticism so here goes:

my($key,$value) = split /[\d]{9}\s+[a-z|A-Z]{1,9}\s+[a-z|A-Z]{1,9}

This looks like you are mixing two concepts, splitting a string and match/capture on a string. Split's first argument is a pattern that matches what separates the things you want in the string, and it returns those things. You might want this:

my($key, @values) = split / /, $this_line

That'll put the '777666555' field into $key, and stuff all the other fields into the array. As far as getting that array into a hash (making the hash have multiple values), I'd check out perldoc perldsc. It is a good tutorial for Perl's compound data structures.

But, like I said, there are some wonky things with your example code that I'd clean up before doing anything else. (Another sort of mixed concept thing going on is that you try to dump INPUT into an array the line before you open it, and then later try to iterate over INPUT anyway.) You can fix several problems (like the missing greater than on while(<INPUT>) just by trying to run the above, Perl will choke, die, and give you pretty verbose error messages.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-18 16:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found