in reply to Loading Hash From FileHandle - Cannot Chomp Input Keys
Untested, should work fine. Not really sure if the defined() test is really necessary, but I figured I'd slip it in.
#!perl -w use strict; my %person = map { m!^(.*)$!; defined($1) and length($1) ? ($1 => 1) : () } <DATA>; __DATA__ Ruth Samuel Paul John Silas
quick update: a simple loop would also work of course:
#!perl -w use strict; my %person; while ( chomp($_ = <DATA>) ) { $person{$_} = 1; } __DATA__ Ruth Samuel Paul John Silas
|
|---|