in reply to Hash from a file
use strict; use warnings; my $file = 'file.txt'; open(my $fh, '<', $file) or die("Unable to open input file \"$file\": $!\n"); my %hash; while (<$fh>) { chomp; my ($dtype, $rest) = split(/:/, $_, 2); my ($id, $desc) = split(/\t/, $rest, 2); $hash{$id} = $desc; }
or
while (<$fh>) { my ($id, $desc) = /^[^:]*:([^\t]*)\t(.*)$/; $hash{$id} = $desc; }
Update: Fixed the bug naikonta identified.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Hash from a file
by naikonta (Curate) on Oct 04, 2007 at 15:45 UTC |