On Tuesday 22 August 2006 05:32, Owen Cook wrote:
> I am trying to get email addresses out of a Sylpheed address book. The
> output of Dumper is;
>
> $VAR1 = {
>           'attribute-list' => [
>                               {}
>                             ],
>           'first-name' => '',
>           'uid' => '158149473',
>           'cn' => 'Julie Jumper',
>           'address-list' => [
>                             {
>                               'address' => [
>                                            {
>                                              'email' =>
> '[EMAIL PROTECTED]', 'uid' => '158149474', 'remarks' =[1]> '',
>                                              'alias' => ''
>                                            }
>                                          ]
>                             }
>                           ],
>           'last-name' => '',
>           'nick-name' => ''
>         };
>
> I cannot get my head around extracting the 'email' it seems be be buried
> deep inside an array and a hash
>
> Here is an attempt;
>
> #!/usr/bin/perl
>
> use XML::Simple;
> use Data::Dumper;
> use strict;
>
> my $xml = new XML::Simple (KeyAttr=>[], ForceArray => 1);
>
> my $data = $xml->XMLin("ab6.xml");
>
> foreach my $d (@{$data->{person}}) {
>       print $d->{cn};    #<- that works
>         print "\t";
>       print $d->{"address-list"} # <-need to get down to address and email.
>                                # most attempts failed but some gave a
>                                # hash reference
>         print "\n";
>
> }
>
> TIA for any assistance/clues
>
>
> --
> Owen

print "cn='".$VAR1->{'cn'}."'\n";
print "email='".$VAR1->{'address-list'}[0]->{'address'}[0]->{'email'}."'\n";

Work your way down the list counting curly and square brackets.

$VAR1->                 pointer to whole hash
{'address-list'}                hash element
[0]->                           because address-list is an array => [
{'address'}                     hash element of array's first entry
[0]->                           because address is an array
{'email'}                       hash element in 'address's 1st entry
-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000     

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to