I am using the perl Text::csv perl module and IO::Scalar module to get csv data the data is as follows: 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 """""..... "...... i cannot find how i can create a hash record so that i can do a search on "ANY" key from the id col which has multiple values associated(name,sal,post,income,country ,address..$#number_of_columns) so as to obtain all values from any single row of record based on key (id) ---------------------------------------------------------
my $url1="http://xyz.com"; my $content = LWP::Simple::get($url1); my $abc= new IO::Scalar \$content; my $csv = Text::CSV->new(); my $data; while(<$abc>){ if ($csv->parse($_)) { next if (/#(.*?)somedata/);#skip the first line my @columns = $csv->fields();#get the coulmns and the +corresponding row value which are stored in each index of array print "Server id: $columns[0]\n\t Server_Name: $column +s[7]\n";#index 0 stores 21,22 after skipping column names similarly i +ndex 2 stores 23,24 #my %ass=($columns[0],$columns[2])#prints 21=> +23|22=>24 #print "@col1";# } } ---------------------------------------------------------- +-----
code is running fine now what i want to do is get name value pairs for example id |state 2146_oak=>state::GA:;US How do i find single data based on key from the entire hash now i am able to get values for entire row based on key i just want a single value from the entire hash based on the row key. Also suppose we have a value called state =state::GA:;US .I want to do search on the vale and if i find keyword GA in the value string i need to use the key 2146_oak and use it for some purpose .how do i do pattern matching on this. Thnx for the help i am a beginner:) soon will become a Perl monk yipee!!
In reply to store array as a hash by luckysing
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |