On Tue, 22 Aug 2006 09:13:47 +0100 Gary Stainburn <[EMAIL PROTECTED]> wrote:
> 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' => '' > > }; Thanks to all that replied. Here is the script to get at Sylpheed address in a readable form. #!/usr/bin/perl use XML::Simple; #use Data::Dumper; #For debugging use strict; my $xml = new XML::Simple( KeyAttr => [], ForceArray => 1 ); my $data = $xml->XMLin("ab6.xml"); # In form 'addrbook-000006.xml' etc. #print Dumper($data); #For debugging foreach my $d ( @{ $data->{person} } ) { print $d->{cn} . "\t"; print $d->{'address-list'}[0]->{'address'}[0]->{'email'} . "\n"; } And here is a script that will do the same to an LDIF file #!/usr/bin/perl use strict; my $file = shift; #Just pass the first part of the file name. my $ldif_addresses = "/path/to/ldifs/$file.ldif"; #ldif extension added here my $ldif_sorted = "/path/to/writeto/$file.sorted"; open( FH, "$ldif_addresses" ) or die "cant open $ldif_addresses $!\n"; open( OF, ">$ldif_sorted" ) or die "cant open $ldif_addresses $!\n"; while (<FH>) { chomp; my $line = $_; if ( $line =~ /cn: / ) { print OF "$'\t"; } if ( $line =~ /mail: / ) { print OF "$'\n"; } } close OF; close FH; open( FH, "$ldif_sorted" ) or die "cant open $ldif_sorted $!\n"; my @list = <FH>; print " "; @list = sort { $a cmp $b } @list; print "@list"; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>