Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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"; }

In reply to Zaurus addressbook.xml parser by Ryszard

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2023-06-10 10:06 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (38 votes). Check out past polls.