more useful options | |
PerlMonks |
Re^3: Reading file into a hash (last record problem)by LanX (Saint) |
on May 28, 2014 at 15:14 UTC ( [id://1087669]=note: print w/replies, xml ) | Need Help?? |
Thats a very common problem, you are trying to add a record only when the successor is to be parsed, but the last record has no successor (sic ;)! Most people try to solve by repeating code to add the last record after the loop. But it's much cleaner this way (avoiding a posteriori state logic) output
Cheers Rolf ( addicted to the Perl Programming Language)
updatea *general pattern* to solve such problems while staying DRY is to use references
like this you don't need to repeat the path of a deeply nested data structure, which might vary in multiple dimensions
updateadded some explanation
In Section
Seekers of Perl Wisdom
|
|