hello,I wrote it as below simply,maybe it's not so good,you could modify it.
use strict; use warnings; my %hash; while(<>) { next if /^$/; if (/Name\s+(.*)$/) { my $name = $1; my $age = $1 if ($_ = <>) =~ /AGE\s+(.*)$/; my $book = $1 if ($_ = <>) =~ /Book\s+(.*)$/; $hash{$name}->{age} = $age; $hash{$name}->{book} = $book; } } # then print the value -----Original Message----- From: anand kumar <[EMAIL PROTECTED]> Sent: Feb 15, 2006 10:33 PM To: beginners@perl.org Subject: Re: hash array Hi , Thanks for the reply. but can u help me out if the data is large and need a loop to store(also if possible give instructions if the record has variable or optional number of fields). Jeff Pang <[EMAIL PROTECTED]> wrote: Name ABC AGE 25 Book perl Name DEF AGE 20 Book linux Name GHI AGE 21 Book PHP ................. can anyone help me on how to store the data with hash key as the 'Name' and the hash strings as the details of 'AGE' and 'Book' Hello,I think you could do it as following: my %hash = ( 'ABC' => { 'AGE' => 25, 'Book' => 'perl', }, 'DEF' => { 'AGE' => 20, 'Book' => 'linux', }, ); Then,you could access the final value,for example the 'perl',with this syntax: print $hash{'ABC'}->{'Book'}; if you want to access all the value of 'ABC',you can do: print $_," ",$hash{'ABC'}->{$_},"\n" for (keys %{$hash{'ABC'}}); Hope that helps. -- Jeff Pang NetEase AntiSpam Team http://corp.netease.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------- Jiyo cricket on Yahoo! India cricket Yahoo! Messenger Mobile Stay in touch with your buddies all the time. -- Jeff Pang NetEase AntiSpam Team http://corp.netease.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>