in reply to (Ovid - Dang, I love this place -- and one more question :)
in thread Typeglobs and Symbol tables
Ah, better. This:
deserves a bit of "improvement". I'll go through step-wise as I hope that will be more enlightening.params { my ( $self, $cgi ) = @_; my %formdata; $cgi = CGI::self_or_default if ( ! defined $cgi or ! ref $cgi ) an +d $cgi; if ( defined $cgi and $cgi ) {
I was not able to understand this: $cgi = CGI::self_or_default if ( ! defined $cgi or ! ref $cgi ) and $cgi; so I did some "mechanical" translation which made it easy for me to understand (this may have more to do with the strange ways in which my mind works, though): $cgi = CGI::self_or_default if $cgi and ! ( defined $cgi and ref $cgi ); So we don't want to override $cgi if it is false and we don't want to override $cgi if it is a good reference. But, my testing shows that ref $cgi doesn't produce a warning even if $cgi is undef so we can shorten this to: $cgi = CGI::self_or_default if $cgi and ! ref $cgi;
Similarly, $cgi in a "Boolean context" doesn't elicit a warning in the face of undef so: if ( defined $cgi and $cgi ) { can become: if ( $cgi ) {
This brings us to:
But I'd factor out the if($cgi):params { my ( $self, $cgi ) = @_; my %formdata; $cgi = CGI::self_or_default if $cgi and ! ref $cgi; if ( $cgi ) {
Finally you can swap if ! with just unless, but I find that mostly a matter of taste.if ( $cgi ) { $cgi = CGI::self_or_default if ! ref $cgi;
Well, anyway, that "works" better for me. (:
- tye (but my friends call me "Tye")
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(Ovid) Re: (tye)Re: (Ovid - Dang, I love this place :-)
by Ovid (Cardinal) on Jun 02, 2001 at 00:19 UTC |