in reply to Network Programming With Perl example 1

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

Replies are listed 'Best First'.
Re^2: Network Programming With Perl example 1
by Anonymous Monk on May 01, 2005 at 02:50 UTC
    Originally the code was verbatim but I changed it because it didn't work. Even using your code doesn't work.

    Now using

    #!/usr/bin/perl #use warnings; #use strict; use IO::Socket; my $server = shift; my $fh = IO::Socket::INET->new($server) or die "Error: $!"; my $line = <$fh>; print $line;
    and getting
    C:\Documents and Settings\admin\Desktop\Scripts>perl network.pl mail.h +otmail.com:smtp Error: Unknown error at network.pl line 8. C:\Documents and Settings\admin\Desktop\Scripts>

      Sorry, I forgot that on Windows you should use $^E instead of $! for the error message. This won't solve your problem, but at least it may get you a more informative error message than what you got with $!.

      the lowliest monk

      Works for me (on Windows 98 with Perl 5.6.1):
      (using your code)
      C:\perl>perl test.pl mail.hotmail.com:smtp 220 mc9-f39.hotmail.com Sending unsolicited commercial or bulk e-mail +to Microso ft's computer network is prohibited. Other restrictions are found at h +ttp://priv acy.msn.com/Anti-spam/. Violations will result in use of equipment loc +ated in Ca lifornia and other states. Sat, 30 Apr 2005 20:00:05 -0700

      chas
        Well what in the world can be going wrong? Do you think I should re-install Perl? I have 5.8x.