in reply to Getting values from a hash, using a string taken from a .csv file as the value
#!/usr/bin/perl use warnings; use strict; my %fruit; open my $FRUIT, '<', 'fruit.csv' or die $!; while (<$FRUIT>) { my @line = split /,/; my($fruit_name, $number) = @line; $fruit{$fruit_name} = $number; } close $FRUIT; open my $FRUITNAMES, '<', 'fruit_names.csv' or die $!; while (<$FRUITNAMES>) { chomp; my @line = split /,/; my $thefruitsname = $line[0]; warn ": $thefruitsname"; my $thenumber = $fruit{$thefruitsname}; print "the number of $thefruitsname is $thenumber\n"; }
Also use indentation, 3 argument open + or die, and strict as shown in the script.
|
|---|