Re: chomp hash keys?



usenet@xxxxxxxxxxxxxxx <usenet@xxxxxxxxxxxxxxx> wrote:
According to perldoc -f chomp:
>> If VARIABLE is a hash, it chomps the hash's values, but not its
keys.

Is there an easy way to "overcome" this?


You can't change a key in the context of a hash, because the
key is the index.

You can create a new element with a newlineless key and delete
the element with the newlined key.


chomp (my %person = (<DATA>));

The keys, of course, have linefeeds on the end, which I do not want.
What is the best way to populate my hash with linefeed-ed data?


my %person = map {chomp; $_} <DATA>;


--
Tad McClellan SGML consulting
tadmc@xxxxxxxxxxxxxx Perl programming
Fort Worth, Texas
.