In that case (and you may already have this worked out)
if you are building one great big hash,
the main code would look something like:
open HANDLE, 'testhash.txt' or die "Can't open: $!";
my %hash;
for my $data (<HANDLE>) {
chomp $data;
foreach my $pair (split /'/, $data) {
next if $pair eq '';
next if $pair =~ /^,$/;
my ($key, $value) = split /,/, $pair;
$hash{$key} = $value;
}
}
close HANDLE;
# do stuff with entire hash here
Or if you are doing something with the hash line-by-line:
open HANDLE, 'testhash.txt' or die "Can't open: $!";
for my $data (<HANDLE>) {
chomp $data;
my %hash;
foreach my $pair (split /'/, $data) {
next if $pair eq '';
next if $pair =~ /^,$/;
my ($key, $value) = split /,/, $pair;
$hash{$key} = $value;
}
# do interesting things with one-line %hash here
}
close HANDLE;
|