After reading posts from fellow monks, see the following snippet. Beware, it is a "naive" approach.... but should work for a one time script.
use strict; use warnings; # we don't want to get burned by stupid mistakes # use autodie; # so that I can omit checking if open failed or succeeded. # not 100% bulletproof, but pretty damned close. use Data::Dumper; # https://metacpan.org/pod/Data::Dumper open my $file, '<', 'file1'; # we assume that the file in question exists, is named 'file1', and is + in current folder my %line_hash = map { chomp; $_ => undef } <$file>; # create a hash out of lines in file. # best read from right to left. # <$file> = get all lines from file as an array # chomp = get rid of end of line character(s) # map = create key value pair, where key is the line # # see http://www.perlmonks.org/?node_id=20505 print Dumper \%line_hash; # does it work?
In reply to Re: Load a single column file into a hash
by jahero
in thread Load a single column file into a hash
by vighneshmufc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |