[aklug] Re: perl doesn't natively do booleans?????

From: Arthur Corliss <acorliss@nevaeh-linux.org>
Date: Wed Aug 18 2010 - 01:37:54 AKDT

On Wed, 18 Aug 2010, Michael Fowler wrote:

> Please, stop doing this. That ($) is a Perl prototype; prototypes in
> Perl are not like any other language. They are intended for use in
> changing how your subroutine call is -parsed-; they are not intended for
> use as validation.
>
> For example:
>
> sub foo ($) { print "@_\n" }
> my @x = qw( a b c );
> foo(@x);
>
> This code prints 3.
>
> Basically, never use prototypes. I can dig up links to describe in
> detail what they're really for, but their uses are very specialized.

I would alter that to say only use prototypes if you fully understand how
Perl implements them. They are very handy and I use them often,
particularly because it (again) can help with consistency (accidentally
leaving out an argument in a function call, for instance), or sometimes
because, darn it, my sub just wants an array reference.

Prototypes have their place in Perl. But they're by no means fully
functionally equivalent with prototypes in other languages.

> Given you aren't actually looking for this in text, then using
> inet_aton() or inet_pton() to validate your IP address would also be a
> good idea. There are many things that can be treated as a valid IP
> address that are not simply a dotted quad.

Actually, you've overlooked a corner case with inet_aton as well:
inet_aton will take names in addition to string representations
of IP addresses and attempt to resolve them via DNS. This may or may not be
a desireable effect.

         --Arthur Corliss
           Live Free or Die
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Wed Aug 18 01:38:02 2010

This archive was generated by hypermail 2.1.8 : Wed Aug 18 2010 - 01:38:02 AKDT