Here is some working code to get you started:
use strict; use warnings; use Data::Dumper; my @colNames; my %all; # Collect server info while (<DATA>){ 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 slic +e 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
Output:
Info for ID=21: $VAR1 = { 'country' => 'US', 'sal' => '23', 'post' => 'lawyer', 'name' => 'hhdh', 'id' => '21', 'income' => '0', 'address..$#number_of_columns' => 'GA' }; Info for ID=22: $VAR1 = { 'country' => 'US', 'sal' => '24', 'post' => 'perl programmer', 'name' => 'shjhds', 'id' => '22', 'income' => '999999999999', 'address..$#number_of_columns' => 'TX' }; Programmer is ID# 22
Update: Added FIND code.

     Syntactic sugar causes cancer of the semicolon.        --Alan Perlis


In reply to Re: hash of hash by NetWallah
in thread hash of hash by luckysing

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.