FAQ
Hello,

I am trying to query a service using a perl script with Net::Telnet.
The first response of the server I am checking has three lines. For
example:

Service Name
Date
hello...

When I use the following syntax, I get only the first line:

$line = $service->getline;
print $line;

If I add the following, I get all three lines:

$line = $service->getline;
print $line;
$line = $service->getline;
print $line;
$line = $service->getline;
print $line;

So I thought if I assigned the value of $service->getline to an array
it would work:

@lines = $service->getline;
print @lines;

So I looked at the Net::Telnet docs again and saw that "getlines" will
return the next available lines so I tried this:

@lines = $service->getlines;
print @lines;

Which returns nothing. In fact, it times out. Can anyone offer any
advice or an example of how to use the getlines function or a more
elegant way to get all of the lines of the greeting?

I would also like an example of how to use a while loop to grab all of the data from @lines or $line until it stops sending:

while ($rrp->getline) {
print;
}

This fails because no end of data is sent after the greeting. Without this, I have to know the format of the response from the server ahead of time.

Thanks for any help,

Random Jack

Search Discussions

  • Mark G at Jun 9, 2003 at 11:28 pm

    Which returns nothing. In fact, it times out. Can anyone offer any
    advice or an example of how to use the getlines function or a more
    elegant way to get all of the lines of the greeting?
    Y not use the geline rutine like this:

    <~~ cut
    #untested
    while( $line = $service->getline ){
    push @lines,$line;
    next if( $line =~ m/last line/ );
    }

    <~~~ paste

    ----- Original Message -----
    From: <perl@fatadmin.com>
    To: <beginners@perl.org>
    Sent: Monday, June 09, 2003 5:44 PM
    Subject: Net::Telnet -> getline(s)

    Hello,

    I am trying to query a service using a perl script with Net::Telnet.
    The first response of the server I am checking has three lines. For
    example:

    Service Name
    Date
    hello...

    When I use the following syntax, I get only the first line:

    $line = $service->getline;
    print $line;

    If I add the following, I get all three lines:

    $line = $service->getline;
    print $line;
    $line = $service->getline;
    print $line;
    $line = $service->getline;
    print $line;

    So I thought if I assigned the value of $service->getline to an array
    it would work:

    @lines = $service->getline;
    print @lines;

    So I looked at the Net::Telnet docs again and saw that "getlines" will
    return the next available lines so I tried this:

    @lines = $service->getlines;
    print @lines;

    Which returns nothing. In fact, it times out. Can anyone offer any
    advice or an example of how to use the getlines function or a more
    elegant way to get all of the lines of the greeting?

    I would also like an example of how to use a while loop to grab all of the
    data from @lines or $line until it stops sending:
    while ($rrp->getline) {
    print;
    }

    This fails because no end of data is sent after the greeting. Without
    this, I have to know the format of the response from the server ahead of
    time.
    Thanks for any help,

    Random Jack


    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedJun 9, '03 at 9:48p
activeJun 9, '03 at 11:28p
posts2
users2
websiteperl.org

2 users in discussion

"": 1 post Mark G: 1 post

People

Translate

site design / logo © 2021 Grokbase