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:
...and it works fine:use IO::Socket; my $server = shift; my $fh = IO::Socket::INET->new($server); my $line = <$fh>; print $line;
To make it a bit more informative, I would change the line where $fh is initialized to% 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
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:my $fh = IO::Socket::INET->new($server) or die "Socket open failed: $^ +E\n";
% 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.:
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.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 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 | |
by tlm (Prior) on May 01, 2005 at 02:58 UTC | |
by chas (Priest) on May 01, 2005 at 03:01 UTC | |
by Anonymous Monk on May 01, 2005 at 03:10 UTC | |
by chas (Priest) on May 01, 2005 at 03:18 UTC | |
by Anonymous Monk on May 01, 2005 at 03:33 UTC | |
|