in reply to Re: Re^2: Stopping and restarting a loop
in thread stoping and restarting a loop
In most cases, though, you can just do direct assignment, mapping your params to @_ in a single declaration. If you have some sort of sick monstrosity that takes so many paramters you have to split up the declaration on to two lines, maybe you should re-think your interface. Once you're past six arguments, things get hard to parse.sub new { my $class = shift; my $self = bless ({ @_ }, $class); # Hash-style params return $self; } sub fooge_default { my $self = shift; $self->fooge(@_); # Blind parameter passing }
What's wrong with this? What if undef was a valid parameter? You've destroyed the evidence, so to speak. I'd try to use this instead:sub fooge { my ($foo, $bar) = (shift, shift); die "fooge() needs two arguments\n" unless (defined($bar)); # ... }
This version distinguishes between undef and not provided.sub fooge { my ($foo, $bar) = @_; die "fooge() needs two arguments\n" unless (@_ == 2); # ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re^4: Shifty Politics
by BrowserUk (Patriarch) on Sep 10, 2002 at 08:37 UTC | |
by tadman (Prior) on Sep 10, 2002 at 15:46 UTC | |
by BrowserUk (Patriarch) on Sep 10, 2002 at 19:38 UTC | |
by tadman (Prior) on Sep 10, 2002 at 22:23 UTC | |
by BrowserUk (Patriarch) on Sep 10, 2002 at 23:00 UTC | |
|