Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
$VAR1 = [ { 'xml_api_reply' => { '-version' => '1', 'weather' => { '-row' => '0', 'current_conditions' = +> { + 'icon' => { + '-data' => '/ig/images/weather/mostly_cloudy.gif' + }, + 'temp_f' => { + '-data' => '73' + }, + 'temp_c' => { + '-data' => '23' + }, + 'wind_condition' => { + '-data' => 'Wind: NW at 6 mph' + }, + 'humidity' => { + '-data' => 'Humidity: 73%' + }, + 'condition' => { + '-data' => 'Mostly Cloudy' + } + }, , 'forecast_information' + => { + 'forecast_date' => { + '-data' => '2012-08-16' + }, + 'city' => { + '-data' => 'Miami, FL' + }, + 'latitude_e6' => { + '-data' => '' + }, + 'postal_code' => { + '-data' => '02151' + }, + 'current_date_time' => { + '-data' => '2012-08-16 12:54:00 +0000' + }, + 'longitude_e6' => { + '-data' => '' + }, + 'unit_system' => { + '-data' => 'US' + } + }, } } }, { 'xml_api_reply' => { '-version' => '1', 'weather' => { '-row' => '0', 'current_conditions' = +> { + 'icon' => { + '-data' => '/ig/images/weather/mostly_cloudy.gif' + }, + 'temp_f' => { + '-data' => '73' + }, + 'temp_c' => { + '-data' => '23' + }, + 'wind_condition' => { + '-data' => 'Wind: NW at 6 mph' + }, + 'humidity' => { + '-data' => 'Humidity: 73%' + }, + 'condition' => { + '-data' => 'Mostly Cloudy' + } + }, 'forecast_information' + => { + 'forecast_date' => { + '-data' => '2012-08-16' + }, + 'city' => { + '-data' => 'Boston, MA' + }, + 'latitude_e6' => { + '-data' => '' + }, + 'postal_code' => { + '-data' => '01908' + }, + 'current_date_time' => { + '-data' => '2012-08-16 12:54:00 +0000' + }, + 'longitude_e6' => { + '-data' => '' + }, + 'unit_system' => { + '-data' => 'US' + } + }, } } }, ];
my $test_data = $data[0]{'xml_api_reply'}{'weather'}{'forecast_informa +tion'}{'city'}->{"-data"};
.... my %hash; open my $fh, '<', 'weather.txt' or die "Cannot open: $!"; while (my $lines = <$fh>) { my @data = $lines; my $key = shift @data; my $test_data = $data[0]{'xml_api_reply'}{'weather'}{'forecast_infor +mation'}{'city'}->{"-data"}; print "$test_data\n"; } close $fh;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Open and parsing a file with array of hashes!?
by hbm (Hermit) on Aug 16, 2012 at 15:08 UTC | |
by Anonymous Monk on Aug 16, 2012 at 15:25 UTC | |
by hbm (Hermit) on Aug 17, 2012 at 00:10 UTC | |
|
Re: Open and parsing a file with array of hashes!?
by Anonymous Monk on Aug 16, 2012 at 14:55 UTC | |
|
Re: Open and parsing a file with array of hashes!?
by stonecolddevin (Parson) on Aug 16, 2012 at 16:32 UTC | |
by Anonymous Monk on Aug 16, 2012 at 17:33 UTC | |
|
Re: Open and parsing a file with array of hashes!?
by linuxkid (Sexton) on Aug 16, 2012 at 15:23 UTC |