|
Posted by Ben Morrow on July 17, 2008, 10:46 pm
Please log in for more thread options
>
> > Huh? The sub defaults to operating on $_ if no argument is supplied.
> > That's hardly an 'edge case'.
>
> What sub? Here's the original code:
>
> my($text) = @_;
> if ($text)
> {
> $$text =~ s/^\s+//;
> $$text =~ s/\s+$//;
> }
> else
> {
> s/^\s+//;
> s/\s+$//;
> }
>
> This means that if the first argument evaluates to "false" (which is
> not at all the same as "not supplying an argument"), the else clause is
> executed and $_ is modified. IMHO that seems like very sloppy and
> unusual coding.
Well, yes, the code posted is obviously incomplete. Bad OP, no cookie.
However, it is obviously expected that the argument will be a ref, which
is always true, so there's no need to check for anything more
complicated. Indeed, if the sub were prototyped (;$) this would be
guaranteed: since explicitly passing a scalar ref to a function is
rather unusual (though not unknown), I would wager that is the case.
Ben
--
Musica Dei donum optimi, trahit homines, trahit deos. |
Musica truces mollit animos, tristesque mentes erigit. | ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras. |
|