http://www.perlmonks.org?node_id=1009773

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I was trying to assing a value to $hash{'AirIATA'} but was failing and then used @hash{'AirIATA'} and voila, it worked but I got a warning as "Scalar value @hash{'AirIATA'} better written as $hash{'AirIATA'} at makeAnnounce.pl line 31."

So, what is wrong or what is right ?

Here is the problematic part of my code;

file1;
@hash{'AirIATA'}=get_IATA($airlineLoc,$hash{'Airline'}); my $letter1 = substr($hash{'AirIATA'},0,1); my $letter2 = substr($hash{'AirIATA'},1,2); print $letter1,"\n",$letter2,"\n";

------------

file2;
sub get_IATA { my $file = shift; my $airline = shift; my @data; my $count=0; open(my $fh, '<', $file) or die "Can't read file '$file' [$!]\ +n"; while (my $line = <$fh>) { my @fields = split(/;/, $line); push @data, @fields; } foreach my $data ( @data) { if ($data eq $airline) { return $data[$count-1],"\n"; } $count++; } }