#!/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."
In reply to Loading Hash From FileHandle - Cannot Chomp Input Keys by roho
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |