|
|
| The stupid question is the question not asked | |
| PerlMonks |
Re^5: How can I group lines in a file?by BrowserUk (Patriarch) |
| on May 17, 2009 at 07:00 UTC ( [id://764487]=note: print w/replies, xml ) | Need Help?? |
|
Why does this line work? /(\S+)\s+(\S+)/ and push @{ $HoA{ $1 } }, $2 while <$fh>; The regex matches against $_ (which is set to each line in turn by the while), and sets $1 to the first whitespace delimited 'word', and $2 to the second. The and checks that the line matches, and if it does pushes the second 'word' onto an array within the hash keyed by the first word. You can also tighten the regex a tad and add some error checking:
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||