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++; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Warning is right or not ?
by davido (Cardinal) on Dec 20, 2012 at 19:02 UTC | |
Re: Warning is right or not ?
by RichardK (Parson) on Dec 20, 2012 at 19:47 UTC | |
by Anonymous Monk on Dec 20, 2012 at 19:54 UTC | |
Re: Warning is right or not ?
by tobyink (Canon) on Dec 20, 2012 at 18:59 UTC | |
Re: Warning is right or not ?
by AnomalousMonk (Archbishop) on Dec 20, 2012 at 20:14 UTC | |
by Anonymous Monk on Dec 21, 2012 at 07:43 UTC | |
by AnomalousMonk (Archbishop) on Dec 21, 2012 at 22:07 UTC | |
by Anonymous Monk on Dec 23, 2012 at 19:13 UTC | |
Re: Warning is right or not ?
by frozenwithjoy (Priest) on Dec 20, 2012 at 19:01 UTC | |
Re: Warning is right or not ?
by Anonymous Monk on Dec 20, 2012 at 19:50 UTC | |
Re: Warning is right or not ?
by Anonymous Monk on Dec 20, 2012 at 19:59 UTC |
Back to
Seekers of Perl Wisdom