I'm doing my first steps in trying to play around with Perl to tweak my LMS. Therefore I was trying to query the # of players. I found some example code that is doing it that way:
# Get the number of players
my @playerIds;
my $playerCount = sendAndReceive('player count ?');
$debug && print "$playerCount players found\n";
for (my $i = 0; $i < $playerCount; $i++) {
$playerIds[$i] = sendAndReceive('player id $i ?');
$debug && print "Player $i has ID $playerIds[$i]\n";
}
Running the script returns the error:
Undefined subroutine &main::sendAndReceive called at ./get_playerids.pl line 23.
What is wrong? It worked for others!
Results 1 to 5 of 5
-
2012-01-10, 15:54 #1
Perl script error - undefined subroutine
Synology DS410j • 4TB • CPU 800 MHz • RAM 128 MB • FW 4.0 - 2198 • Platform armv5tel-linux (MARVELL_88F6281)
LMS 7.7.2 - r33893 | Perl 5.8.6 | SQLite 1.34_01 (sqlite 3.7.5)
ASUS P6-P5G41E W7 x64 | LMS 7.8.0 - 1370874416 | Perl 5.14.1 | SQLite 1.34_01 (sqlite 3.7.7.1)
3 SB Radios | 2 SB Receivers | Samsung Galaxy S Advance | Squeeze Player 1.3.7 & Squeeze Commander 0.9.6.4 | XELIO 7" with Squeeze Commander
-
2012-01-13, 13:56 #2
Perl script error - undefined subroutine
> Undefined subroutine &main::sendAndReceive called at ./get_playerids.pl
> line 23.
As the message says: sendAndReceive most likely isn't defined in your script.
--
Michael
-
2012-01-14, 09:58 #3
That's right.
I was assuming that this is a function provided by LMS. Before the above mentioned code I declare the following:
my $socket = IO::Socket::INET->new (PeerAddr => $serverAddress,
PeerPort => $serverPort,
Proto => 'tcp',
Type => SOCK_STREAM)
or die 'Couldn\'t connect to server';
If this is not the case, I wonder how it worked for the example got the idea from http://forums.slimdevices.com/showpo...95&postcount=6
Any idea?Synology DS410j • 4TB • CPU 800 MHz • RAM 128 MB • FW 4.0 - 2198 • Platform armv5tel-linux (MARVELL_88F6281)
LMS 7.7.2 - r33893 | Perl 5.8.6 | SQLite 1.34_01 (sqlite 3.7.5)
ASUS P6-P5G41E W7 x64 | LMS 7.8.0 - 1370874416 | Perl 5.14.1 | SQLite 1.34_01 (sqlite 3.7.7.1)
3 SB Radios | 2 SB Receivers | Samsung Galaxy S Advance | Squeeze Player 1.3.7 & Squeeze Commander 0.9.6.4 | XELIO 7" with Squeeze Commander
-
2012-01-14, 10:01 #4Senior Member
- Join Date
- Oct 2005
- Location
- Ireland
- Posts
- 11,258
It's provided in the message you reference just you need to scroll down. It looks like you didn't copy all the code from the source.
Code:# Send given cmd to $socket and return answer with original command removed from # front if present. Routine nicked from code by Felix Mueller. :-) sub sendAndReceive { my $cmd = shift; return if( $cmd eq ""); print $socket "$cmd\n"; $debug > 1 && print "Sent $cmd to server\n"; my $answer = <$socket>; $debug > 1 && print "Server replied: $answer\n"; $answer =~ s/$cmd //i; $answer =~ s/\n//; return $answer; }
-
2012-01-14, 10:15 #5Synology DS410j • 4TB • CPU 800 MHz • RAM 128 MB • FW 4.0 - 2198 • Platform armv5tel-linux (MARVELL_88F6281)
LMS 7.7.2 - r33893 | Perl 5.8.6 | SQLite 1.34_01 (sqlite 3.7.5)
ASUS P6-P5G41E W7 x64 | LMS 7.8.0 - 1370874416 | Perl 5.14.1 | SQLite 1.34_01 (sqlite 3.7.7.1)
3 SB Radios | 2 SB Receivers | Samsung Galaxy S Advance | Squeeze Player 1.3.7 & Squeeze Commander 0.9.6.4 | XELIO 7" with Squeeze Commander

Reply With Quote

