use strict; use warnings; use Data::Dumper; my @colNames; my %all; # Collect server info while (){ my @col = split /,/; for my $c(@col){ $c =~ s/^\s+//; # Strip Leading white space $c =~ s/\s+$//; # Strip trailing white space } if ($col[0] eq "id"){ @colNames = @col; next; } my %info; @info{@colNames} = @col; # Fill the hash, using slice next unless $info{id} ; # ignore lines without valid ID $all{ $info{id} } = [@col]; # Save each row } # Print server info Print_Server_Info (21); Print_Server_Info (22); my $l = find_by_kwd ("post", "perl programmer"); print "Programmer is ID# $l\n"; #--end of program -- sub Print_Server_Info{ my $id = shift @_; my %info; @info{@colNames} = @{ $all{$id} }; # Fill the hash, using slice print "Info for ID=$id:\n" . Dumper \%info; } sub find_by_kwd{ my ($name, $value)=@_; for my $id (keys %all){ my %info; @info{@colNames} = @{ $all{$id} }; # Fill the hash, using slice return $id if $info{ $name } eq $value; } return undef; # Not found } __DATA__ id ,name,sal,post,income,country ,address..$#number_of_columns 21,hhdh,23,lawyer,0,US,GA,XYZ...$#number_of_rows 22,shjhds,24,perl programmer,999999999999,US,TX,XYZ..$#number_of_rows