Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

First time actually trying a module outside of CGI so please bare with me. I'm trying to just setup a simple messaging thing for Net::AOLIM but I'm getting an error running my code. Error: readline() on unopened filehandle. Never experienced this error before and I came up a little short searching for this message on this site.
use strict; use warnings; # require Net::AOLIM; my $user = "---"; my $pass = "---"; my $Version; print "Subject's Name:"; chomp(my $destuser = <STDIN>); print "Message:"; chomp(my $message = <STDIN>); use Net::AOLIM; my $aim = Net::AOLIM->new( 'username' => $user, 'password' => $pass, 'callback' => \&callbackfunction, 'server' => 'toc.oscar.aol.com', 'port' => 1234, 'allow_srv_settings' => <1>, 'login_server' => 'login.oscar.aol.com', 'login_port' => 5198, 'login_timeout' => 0, 'aim_agent' => "AOLIM:$Version VERSION\$"); $aim->signon; $aim->toc_send_im($destuser, $message);

20030411 Edit by Corion: Changed title

Replies are listed 'Best First'.
Re: AOL Messaging
by chromatic (Archbishop) on Apr 09, 2003 at 05:23 UTC

    This line:

    'allow_srv_settings' => <1>,

    tries to read a line from a filehandle named 1 which isn't open. Without looking at the documentation, I suspect you could remove the angle brackets and the error would disappear.

Re: AOL Messaging
by bbfu (Curate) on Apr 09, 2003 at 05:31 UTC

    The reason you get that error is because of the line:

        'allow_srv_settings' => <1>,

    You end up trying to read from the filehandle named 1. You probably meant to say:

        'allow_srv_settings' => 1,

    The angle brackets in the documentation mean that you should use either 1 or 0.

    Also, for this particular case, you shouldn't specify the 'callback' option, since you don't actually define callbackfunction (and don't need to for this simple program). In fact, in general, you shouldn't really need to specify a value for most of the options, as they should have reasonable defaults. You really only need to give it the username and password and it should work correctly.

    Hope that helps.

    bbfu
    Black flowers blossom
    Fearless on my breath

      Ok, thanks. That removed on error and a new error just occured. I get an uninitialized error at @@@@, do you know why? If I remove the my I get the error saying I need to use one under strict but when I get it I get this error.

      Thanks!
      #!/usr/bin/perl use strict; use warnings; # require Net::AOLIM; my $user = "wfgs343R"; my $pass = "iamcool"; my $Version; my $aim; print "Subject's Name:"; chomp(my $destuser = <STDIN>); print "Message:"; chomp(my $message = <STDIN>); use Net::AOLIM; @@@@ $aim = Net::AOLIM->new( 'username' => $user, 'password' => $pass, 'callback' => \&callbackfunction, 'server' => 'toc.oscar.aol.com', 'port' => 1234, 'allow_srv_settings' => 1, 'login_server' => 'login.oscar.aol.com', 'login_port' => 5198, 'login_timeout' => 0, 'aim_agent' => "AOLIM:$Version VERSION\$"); $aim->signon; $aim->toc_send_im($destuser, $message);
        To set aim_agent, you used $Version, which is a variable you my'd earlier, and it is unitialized.

        So you should initialize it, if you want to use it.

        What they actually suggest you to use is $Net::AOLIM::VERSION, which is the version of your AOLIM package. To use this one, you neither need to declare it, nor to initialize it. Those are done for you in the AOLIM package, so you just use it, it is ready for you.
Re: AOL Messaging
by pg (Canon) on Apr 09, 2003 at 05:42 UTC
    I think you get this interesting <1> syntax from the document:
    'allow_srv_settings' => <1 | 0> (default 1)
    However that's not the Perl syntax, what it tells you is that, allow_srv_settings takes a boolean, either 1 or 0. If you don't supply a value, it defaults to 1.

    So you could say:
    'allow_srv_settings' => 1
    Or
    'allow_srv_settings' => 0
    Or simply don't even mention it, which would be the same as saying:
    'allow_srv_settings' => 1