That's not surprising because you changed the code in the example! The actual code provided is:

use IO::Socket; my $server = shift; my $fh = IO::Socket::INET->new($server); my $line = <$fh>; print $line;
...and it works fine:
% perl lgetr.pl mail.hotmail.com:smtp 220 mc5-f26.hotmail.com Sending unsolicited commercial or bulk e-mail +to Microsoft's computer network is prohibited. Other restrictions are + found at http://privacy.msn.com/Anti-spam/. Violations will result i +n use of equipment located in California and other states. Sat, 30 Ap +r 2005 19:25:12 -0700
To make it a bit more informative, I would change the line where $fh is initialized to
my $fh = IO::Socket::INET->new($server) or die "Socket open failed: $^ +E\n";
Then, if you give it an unavailable server, instead of trying to read from an unopened handle, the program prints out an intelligible error message and exits:
% perl lgetr.pl wuarchive.wustl.edu:daytime Socket open failed: Connection refused

Update: s/!/^E/.

If you insist on doing it your way, you need to chomp the input line, and instead of giving the input as a command line argument, you must enter it via standard input. E.g.:

use IO::Socket; my $site = <STDIN>; chomp $site; my $fh = IO::Socket::INET->new($site) or die "Socket open failed: $^E\ +n"; my $line = <$fh>; print $line; __END__ % perl lgetr.pl[HIT RETURN HERE] mail.hotmail.com:smtp[HIT RETURN HERE] 220 mc5-f26.hotmail.com Sending unsolicited commercial or bulk e-mail +to Microsoft's computer network is prohibited. Other restrictions are + found at http://privacy.msn.com/Anti-spam/. Violations will result i +n use of equipment located in California and other states. Sat, 30 Ap +r 2005 19:28:52 -0700
The above works on Linux, at least. I'm not sufficiently familiar with the Windows CLI to be able to say whether it would work exactly like this there.

the lowliest monk


In reply to Re: Network Programming With Perl example 1 by tlm
in thread Network Programming With Perl example 1 by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.