LucaPette has asked for the wisdom of the Perl Monks concerning the following question:
Reading Perl documentation i learned that the chomp function chomps the hash's values, but not its keys.
Obviously that's right but i have used a snippet like the following to build an hash from a file:
chomp (my %an_hash=<A_File>);
And also in this case it chomps only the values.
To obtain an hash from a file with keys and values both chomped i have used a chunk of code like this:
It works but it seems too much complicated, the former snippet don't work fine but it's really short and simple.my %an_hash; while (<A_FILE>) { chomp; chomp(my $tmpvalue=<A_FILE>); $an_hash{$_}=$tmpvalue; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Building a chomped hash from a file
by sauoq (Abbot) on Oct 28, 2005 at 19:35 UTC | |
|
Re: Building a chomped hash from a file
by Errto (Vicar) on Oct 28, 2005 at 19:17 UTC | |
|
Re: Building a chomped hash from a file
by Anonymous Monk on Oct 28, 2005 at 22:12 UTC | |
by sauoq (Abbot) on Oct 30, 2005 at 20:36 UTC |