Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^4: Array to hash converstion

by gem555 (Acolyte)
on Jul 16, 2009 at 10:40 UTC ( #780641=note: print w/replies, xml ) Need Help??


in reply to Re^3: Array to hash converstion
in thread Array to hash converstion

#!/usr/bin/perl -w use strict; use warnings; my @data_list = ( {key => 'correct', value => 'Article_text1'}, {key => 'correct', value => 'Article_text2'}, {key => 'date', value => '2009-01-01'}, {key => 'date', value => '2009-01-02'} ); my @correct; my @date; for my $data_pair (@data_list) { print "Value:$data_pair->{value}:Key:$data_pair->{key}\n"; if($data_pair->{key} eq 'correct'){ @correct = $data_pair->{value}; } if($data_pair->{key} eq 'date'){ @date = $data_pair->{value}; } } print "The array is @correct\n"; print "The array is @date\n";
The array stores only the last value. How to store all the values into array

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://780641]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2020-07-14 22:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?