CUFP
Ryszard
A pretty rough addressbook.xml parser i whipped up. I intend to use it in combination with apache and gnokii to send sms's..
<p>Given the addressbook is actually xml one could probably install one of the many xml parsers available on CPAN, but this is good enuff for me.. :-)</p>
<p>Improvements welcome.. ;-)</p>
<code>
#!/usr/bin/perl -w
use strict;
undef $/;
open(FH, 'addressbook.xml') || die "$!";
my $ab = <FH>;
$ab =~ s/\/\>//g;
my @book = split(/\<Contact/, $ab);
my %addresses;
foreach my $address (@book) {
if ($address =~ /Uid/) {
my $tmp = $address;
$tmp =~ /(Uid\=.+\")/;
my $Uid = $1;
my @fields = split(/\"\s+/ , $address);
foreach my $field (@fields) {
$field =~ s/\"//g;
my @data = split(/=/,$field);
$addresses{$Uid}{$data[0]} = $data[1];
}
}
}
foreach my $Uid (keys %addresses) {
print "$Uid: \n";
foreach (keys %{$addresses{$Uid}} ) {
print " $_=$addresses{$Uid}{$_}\n";
}
print "\n";
}
</code>