Quantcast
Channel: How to access an xml array from Perl? - Stack Overflow
Viewing all articles
Browse latest Browse all 2

How to access an xml array from Perl?

$
0
0

I have a perl script that connects to my Icecast2 server and monitors the list of users. I'm trying to access the list of listeners as an array so that I can perform an action for each listener

Relevant Subroutine:

sub process_list_clients(){        my ($mount) = @_;        my $icecast_mount = Net::Icecast2::Mount->new(            host => $ic_host,            port => $ic_port,            protocol => $ic_protocol,            login    => $ic_login,            password => $ic_password,            mount    => $mount        );        my $xml = $icecast_mount->list_clients;        print STDERR Dumper($xml);        print STDERR "Listeners: " . $xml->{source}->{Listeners} . "\n";        print STDERR "Mount: " . $xml->{source}->{mount} . "\n";        my @listeners = $xml->{source}->{listener};        foreach my $listener (@listeners)        {                print STDERR Dumper($listener);        }}

Output from the subroutine:

Listeners: 6Mount: /masked$VAR1 = [          {'ID' => '233307','Connected' => '705','IP' => 'masked','UserAgent' => 'FreeSWITCH(mod_shout)/1.0'          },          {'ID' => '233336','Connected' => '622','IP' => 'masked','UserAgent' => 'FreeSWITCH(mod_shout)/1.0'          },          {'ID' => '233370','Connected' => '503','IP' => 'masked','UserAgent' => 'FreeSWITCH(mod_shout)/1.0'          },          {'ID' => '233392','Connected' => '433','IP' => 'masked','UserAgent' => 'FreeSWITCH(mod_shout)/1.0'          },          {'ID' => '233419','Connected' => '347','IP' => 'masked','UserAgent' => 'FreeSWITCH(mod_shout)/1.0'          },          {'ID' => '233445','Connected' => '275','IP' => 'masked','UserAgent' => 'FreeSWITCH(mod_shout)/1.0'          }        ];

Here is the xml output from Icecast2:

<icestats><source mount="/masked"><Listeners>7</Listeners><listener><IP>masked</IP><UserAgent>FreeSWITCH(mod_shout)/1.0</UserAgent><Connected>798</Connected><ID>233307</ID></listener><listener><IP>masked</IP><UserAgent>FreeSWITCH(mod_shout)/1.0</UserAgent><Connected>715</Connected><ID>233336</ID></listener><listener><IP>masked</IP><UserAgent>FreeSWITCH(mod_shout)/1.0</UserAgent><Connected>596</Connected><ID>233370</ID></listener><listener><IP>masked</IP><UserAgent>FreeSWITCH(mod_shout)/1.0</UserAgent><Connected>526</Connected><ID>233392</ID></listener><listener><IP>masked</IP><UserAgent>FreeSWITCH(mod_shout)/1.0</UserAgent><Connected>440</Connected><ID>233419</ID></listener><listener><IP>masked</IP><UserAgent>FreeSWITCH(mod_shout)/1.0</UserAgent><Connected>368</Connected><ID>233445</ID></listener><listener><IP>masked</IP><UserAgent>FreeSWITCH(mod_shout)/1.0</UserAgent><Connected>91</Connected><ID>233511</ID></listener></source></icestats>

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images