[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

RE: [FWP] aCertainName.pm



> From: tallwine@carol.ixlabs.com [mailto:tallwine@carol.ixlabs.com]
> Sent: Tuesday, November 09, 1999 09:37
> To: lr@hpl.hp.com
> Cc: etienne@isr.isr.ist.utl.pt; fwp@technofile.org
> Subject: Re: [FWP] aCertainName.pm
>
>
> Larry Rosler said...
> >
> >> From: Etienne Grossmann [mailto:etienne@isr.isr.ist.utl.pt]
> >
> >I don't know what the quotes are for.  And more to the point, why a
> >return value of true/false is appropriate.
> >
> >  sub abs{(my$x=$_[0])=~s/^-//;$x}
> >
> >There.  That's bad enough, but at least it should work right.
>
> Wouldn't this be better?
>
> sub abs {
> 	return 0 unless @_;
> 	 return ($_[0] >= 0)?$_[0]:-$_[0];
> }
>
> And it even runs faster too.

You are trying to be reasonable, but I thought this was all supposed to
be outrageous!

If you want to be reasonable, you might want to get the spec right.  If
there is no argument, abs(), like so many other builtin functions, uses
$_ as its operand.

So at least start out with:

        my $x = @_ ? $_[0] : $_;

Then be as reasonable or as silly as you wish.

--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com



==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe