roho has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; ###################################################################### +###### # First attempt - BAD - Load hash from file handle - keys contain newl +ines. ###################################################################### +###### #my %person = map { $_ => 1 } <DATA>; ###################################################################### +###### # Second attempt - GOOD - Load hash from chomped array - no newlines. ###################################################################### +###### chomp(my @array = <DATA>); my %person = map { $_ => 1 } @array; for (keys %person) { print "$_ = $person{$_}\n"; } __DATA__ Ruth Samuel Paul John Silas
"Its not how hard you work, its how much you get done."
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Loading Hash From FileHandle - Cannot Chomp Input Keys
by bmann (Priest) on Dec 22, 2004 at 02:16 UTC | |
by roho (Bishop) on Dec 22, 2004 at 04:01 UTC | |
|
Re: Loading Hash From FileHandle - Cannot Chomp Input Keys
by saskaqueer (Friar) on Dec 22, 2004 at 01:57 UTC | |
|
Re: Loading Hash From FileHandle - Cannot Chomp Input Keys
by johnnywang (Priest) on Dec 22, 2004 at 03:00 UTC | |
by BUU (Prior) on Dec 22, 2004 at 05:05 UTC |