Your problem is either "ignoring newlines" or "not using a decent CSV parser". Take your pick.
For the first, use chomp:
my %fruit; open my $fh, "<", "fruit.csv") or die; while (<$fh>) { chomp; # THIS IS IMPORTANT HERE my ($fruit_name, $number) = split m/,/ => $_; $fruit{$fruit_name} = $number; # puts key-value pair (apples 5) in +to the hash } close ($fh); open my $fn, "<", "fruit_names.csv" or die; while (<$fn>) { chomp; # DO NOT FORGET my ($thefruitsname) = split m/,/ => $_; my $thenumber = $fruit{$thefruitsname} or die; ... }
In reply to Re: Getting values from a hash, using a string taken from a .csv file as the value
by Tux
in thread Getting values from a hash, using a string taken from a .csv file as the value
by AnnaSpanner
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |