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


in reply to Warning is right or not ?

Here is the result ( and then both running versions);

Output;

[root@testrhel AFAStest]# perl test2.pl #Right now $hash [root@testrhel AFAStest]# vi test2.pl #I change $hash to @hash [root@testrhel AFAStest]# perl test2.pl # Running as @hash Scalar value @hash{'AirIATA'} better written as $hash{'AirIATA'} at te +st2.pl line 12. P C

pl files

test1.pl

#!/usr/bin/perl use warnings; use strict; use XML::Simple; my $programNAME= 'This line is required to work.'; 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++; } }

test2.pl

#!/usr/bin/perl use warnings; use strict; use XML::Simple; require 'test1.pl'; my $airlineLoc = "definitions/airline.csv"; my %hash; @hash{'AirIATA'}=get_IATA($airlineLoc,'PGT'); my $letter1 = substr($hash{'AirIATA'},0,1); my $letter2 = substr($hash{'AirIATA'},1,2); print $letter1,"\n",$letter2,"\n";