SPUG: xml parsing
John W. Krahn
krahnj at telus.net
Wed Oct 4 11:00:34 PDT 2006
luis medrano wrote:
> List,
> I trying to grab the content of xml file is under this tag
> <book:isbn>1-56592-243-3</book:isbn> but I tried to do it like this:
>
> my $isbn=$$item{'book:isbn'};
>
> and returns empty but if I do it like this :
>
> my $isbn=$$item{book:isbn};
>
> it gives me this error:
>
> syntax error at books.pl line 64, near "{book:"
> syntax error at books.pl line 185, near "}"
> Execution of book.pl aborted due to compilation errors.
That is because ':' is not a "word" character and so the key has to be quoted
like your first example. (Only alphanumeric and underscore characters will be
automagically quoted.) Also, the usual way to dereference is:
my $isbn = $item->{ 'book:isbn' };
As to why it is empty, it is hard to say. Could 'item' be an actual hash and
not a hash reference?
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
More information about the spug-list
mailing list