Hi all
I have a problem whereby my foreach will not update a variable ($list) if the hash has only one key
/ value.
Below is my Data Dumper output.
I basically need to do a foreach on
$xmlData->{'misc_links'}->{'activities_list'}->{'activity'}.
Now if I have two or more elements, then its work, but its only if I have one,
then I get nothing.
If anyone could assist me, I would be most grateful.
Kind Regards
Brent Clark
============= Data :: Dumper -==============
$VAR1 = {
'picture_comments' => {
'pic4' => {},
'pic2' => {},
'pic3' => {},
'pic1' => {}
},
'description' => {
'paragraph' => [
'Witbank is Afrikaans for White Ridge and named after
an outcrop of white sandstone where wagon transport drivers rested in earlier times',
'This coal-mining town is situated ideally for
traveling between Gauteng and Mpumalanga provinces.'
]
},
'misc_links' => {
'activities_list' => {
'activity' => 'Witbank Skydiving
Club'
},
'recommended_sites' => {
'sites' => [
'Witbank Dam',
'Witbank Civic
Theatre'
]
},
'history' => 'Witbank was proclaimed a town in 1903 and became a
municipality in 1914.',
'malaria_details' => 'Malaria-free area'
}
};
================= My Code ====================================
foreach $linkName ( sort keys %{$xmlData->{'misc_links'}} ){
if( ref($xmlData->{'misc_links'}->{$linkName}) eq "HASH" ){
# My problem starts here.
foreach $item ( keys %{ $xmlData->{'misc_links'}->{$linkName}} ){
$list = ucfirst join( ", ", sort @{
$xmlData->{'misc_links'}->{$linkName}->{$item} });
}
}
else
{
$list = ucfirst $xmlData->{'misc_links'}->{$linkName};
}
$linkName =~ s/[_]/ /;
$text = "<DIV><P><strong>" . ucfirst $linkName."</strong>:<br />".$list .
"</P></div>";
$rtn_linkList .= $text ;
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>