[Playlist] problem with perl xspf arrays

Ross Mohn rpmohn at waxandwane.org
Wed Jun 13 13:21:38 UTC 2007


Hi,
I'm using XML::XSPF and I'm having trouble using elements that allow
multiple entries such as <identifier> and <link>. It's probably some
basic OO Perl thing, but I can't figure it out. Below is an extension of
the synopsis program from
http://search.cpan.org/~daniel/XML-XSPF/lib/XML/XSPF.pm
to illustrate my problem. I've included the program output, which also
prints out my sample input.

Please help me understand how to use these elements of XSPF!
Thanks in advance! -Ross


PROGRAM:
use strict;
use XML::XSPF;
use XML::XSPF::Track;

my $playlist = XML::XSPF->parse("dummy.xspf");

print "INPUT:\n" . $playlist->toString . "\n";

print "OUTPUT:\n";
for my $track ($playlist->trackList) {
  print "Location: " . $track->location . "\n" if ($track->location);
  print "Title   : " . $track->title    . "\n" if ($track->title);
  print "Link    : " . $track->links    . "\n" if ($track->links);
  print "Link    : " . $track->{links}  . "\n" if ($track->links);
  print "Link    : " . $track->{links}->[0]  . "\n" if ($track->links);
  print "Link    : " . $track->links->[0] . "\n" if ($track->links);
}

INPUT:
<?xml version="1.0" encoding="UTF-8"?>

<playlist version="1" xmlns="http://xspf.org/ns/0/">
    <title>gone with the schwinn</title>
    <creator>kermit the frog</creator>
    <date>2007-06-13T08:28:05-04:00</date>
    <trackList>
        <track>
            <location>http://example.org/Yellow/100.mp3</location>
            <link rel="">http://example.org/Yellow/index.html</link>
            <title>Yellow</title>
        </track>
    </trackList>
</playlist>

OUTPUT:
Location: http://example.org/Yellow/100.mp3
Title   : Yellow
Link    : 1
Link    : ARRAY(0x835f488)
Link    : ARRAY(0x835f5d8)
Can't use string ("1") as an ARRAY ref while "strict refs" in use
at ./dummy.pl line 18.





More information about the Playlist mailing list