Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 5 of 5
  1. #1
    Senior Member doubleugk's Avatar
    Join Date
    Feb 2010
    Location
    Stuttgart - Germany
    Posts
    173

    Question Perl script error - undefined subroutine

    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!
    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)
    3 SB Radios | 2 SB Receivers | Samsung Galaxy S Advance | Squeeze Player 1.3.5 & Squeeze Commander 0.9.6.4 | XELIO 7" with Squeeze Commander

  2. #2
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    18,931

    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

  3. #3
    Senior Member doubleugk's Avatar
    Join Date
    Feb 2010
    Location
    Stuttgart - Germany
    Posts
    173
    Quote Originally Posted by mherger View Post
    > sendAndReceive most likely isn't defined in your script. -- Michael
    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)
    3 SB Radios | 2 SB Receivers | Samsung Galaxy S Advance | Squeeze Player 1.3.5 & Squeeze Commander 0.9.6.4 | XELIO 7" with Squeeze Commander

  4. #4
    Senior Member
    Join Date
    Oct 2005
    Location
    Ireland
    Posts
    11,246
    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;
    }

  5. #5
    Senior Member doubleugk's Avatar
    Join Date
    Feb 2010
    Location
    Stuttgart - Germany
    Posts
    173
    Quote Originally Posted by bpa View Post
    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.
    Thanx - If one can read it's really an advantage ;-)
    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)
    3 SB Radios | 2 SB Receivers | Samsung Galaxy S Advance | Squeeze Player 1.3.5 & Squeeze Commander 0.9.6.4 | XELIO 7" with Squeeze Commander

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •