Well, it is possible to achieve what you want with a one-liner like so:
Also note that there's a very important difference between your proposed code and the actual code. The proposed code reads in the entire file at once into a list in memory (which is also what my code does), whereas the second snippet reads two lines at a time. So it's not just a matter of code aesthetics - it's a matter of what you want your program to do.my %hash = do { chomp(my @lines = <FILE>); @lines };
The reason your proposed snippet doesn't work is that you can't alter the keys in a hash - it really goes against the concept of what a hash is. You can alter the value for a given key, and you can add and delete keys, but it doesn't really make sense to alter a key.
In reply to Re: Building a chomped hash from a file
by Errto
in thread Building a chomped hash from a file
by LucaPette
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |