gem555 has asked for the wisdom of the Perl Monks concerning the following question:
After the if the condition, the values should be pushed to the array#!/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";
I should store all the variables in array and not overwrite after if statementif($data_pair->{key} eq 'correct'){ @correct = $data_pair->{value}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array values are overwritten
by Fletch (Bishop) on Jul 16, 2009 at 12:16 UTC | |
|
Re: Array values are overwritten
by Anonymous Monk on Jul 16, 2009 at 12:32 UTC |