On Thu, Nov 24, 2011 at 7:19 PM, JPH<jph4dot...@xs4all.nl> wrote:
19
20 my $hostname = $ARGV[0];
21 my $portnumber = $ARGV[1];
22 my $host = shift || $hostname;
23 my $port = shift || $portnumber;
I'm not sure what the meaning is of this but the thing that is happening is
simple enough. You have @ARGV which contains [ 'A host name', 'A port
number']. On line 20 you set $hostname = $ARGV[0] = 'A host name' and on
line 21 you set $portnumber = $ARGV[1] = 'A port number'. So far so good,
then on line 22 you assign $host the contents of $_[0] or $hostname, and on
23 you set $host = $_[1] or $portnumber;
this is not the OP's code, but some source he found on the net. and it
is very poor code at that. hand coding socket stuff is not needed when a
simple call to IO::Socket would do it all (including the timeout with no
need for the eval).
Now I am not familiar enough with the perl innards to fully understand the
logic behind this construction, but basically in this setup you will prefer
the use of @_ over the information in @ARGV after all the value after the
|| will only be used in case the shift argument results in an
undef assignment to $host or $port.
there is no @_ involved there as there is no sub being called. the shift
only works on @ARGV there. i bet the author wanted to make the code work
from a sub or as a standalone. there are better ways to do it and this
wasn't even finished for that purpose. the results appear to be nothing
more than the first two lines do.
uri
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/