A pretty rough addressbook.xml parser i whipped up. I intend to use it in combination with apache and gnokii to send sms's..
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.. :-)
Improvements welcome.. ;-)
#!/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"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Zaurus addressbook.xml parser
by davido (Cardinal) on Nov 20, 2003 at 17:57 UTC | |
by Ryszard (Priest) on Nov 20, 2003 at 19:17 UTC | |
Re: Zaurus addressbook.xml parser
by Aristotle (Chancellor) on Nov 22, 2003 at 08:40 UTC | |
by Ryszard (Priest) on Nov 22, 2003 at 16:19 UTC | |
Re: Zaurus addressbook.xml parser
by William G. Davis (Friar) on Nov 20, 2003 at 17:51 UTC |
Back to
Cool Uses for Perl