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?? |
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_lineThat'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.
In Section
Seekers of Perl Wisdom
|
|