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

I looked every where on how to get a TELNET connection up and running, but everywhere I look it is something different and never works.

This is the best I got so far:

#!c:\strawberry\perl\bin\perl -w use CGI::Carp qw( fatalsToBrowser ); use Net::Telnet (); print "Content-type:text/html\r\n\r\n"; $telnet = new Net::Telnet; $telnet->open([Host => 'localhost',] [Port => '7300',] [[Errmode => 'd +ie',] [Timeout => '9']); $telnet->waitfor('/Please enter your callsign: $/i');
#########

but I get an error of : syntax error at C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/telnet,pl line 9, near "] ["

Missing right curly or square bracket at C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/telnet,pl line 20, at end of line

##########

it states that I am Missing right curly bracket, but I do not even have a LEFT one????

Replies are listed 'Best First'.
Re: Just trying to TELNET
by NetWallah (Canon) on Dec 26, 2012 at 04:29 UTC
    Welcome to the monastery !

    Please correct your post , using <code> tags, and post your code un-altered, so we can see what it looks like (See Writeup Formatting Tips).

    At present, it is mangled, so it is impossible to advice, save that the perl message is most likely correct - you have an extra left bracket "[" somewhere.

    One thing you can try is to run the code from a command line, rather than via CGI - at lease till you pass syntax checking.

                 "By three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest."           -Confucius

Re: Just trying to TELNET
by keszler (Priest) on Dec 26, 2012 at 05:04 UTC
    It's possible I'm seeing something other than what you intended - please edit your post using the guidelines at Writeup Formatting Tips - but from what appears I see an opening square bracket before the Errmode term. The error message says you're "Missing right curly or square bracket...". Is there a closing square bracket after the Timeout term?
Re: Just trying to TELNET
by zentara (Cardinal) on Dec 26, 2012 at 12:24 UTC
    it states that I am Missing right curly bracket, but I do not even have a LEFT one????

    Missing right curly or square bracket at

    Yeah, the error message says that if you try to start an anonymous array grouping with a left bracket, the code needs a right bracket somewhere to close it off. You need to read between the lines in those error messages. :-) Here is your left bracket.

    Port => '7300', [Errmode => 'die', Timeout => '9'); #My guess is that it should look like this: Port => '7300', [Errmode => 'die', Timeout => '9'] );
    Also, I don't think you need single quotes around '7300' as 7300 is a number not a string.

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      That solved the MISSING RIGHT CURLY BRACKET, but now it states that here is a syntax error near Port.
        use diagnostics;

        When the messages generated with use strict; use warnings; are beyond your understanding, add diagnostics to your arsenal. See also perldoc splain.

        OK got it to work with the following code:
        $telnet = new Net::Telnet ( Timeout=>10, Port=>7300, Errmode=>'die'); $telnet->open('localhost')
        Thanks for your help, it is appreciated