in reply to Re^4: Shifty Politics
in thread stoping and restarting a loop
Thanks. This and Shift versus Sanity are very interesting. I'm still learning all the why's and wherefor's of perl syntax and semantics. I probably will be for some time to come. I will just about have mastered it, and Perl6 will hit the streets! Hopefully, enough of it will carry over to not invalidate the exercise.
A couple of questions arising:
Wouldn't this
sub fooge_default { my $self = shift; $self->fooge(@_); # Blind parameter passing }
be better done as this?
sub fooge_default { my $self = shift; goto &$self->fooge; # Not entirely sure of the syntax }
vis
The goto-&NAME form is highly magical, and substitutes a call to the named subroutine for the currently running subroutine. This is used by AUTOLOAD() subroutines that wish to load another subroutine and then pretend that the other subroutine had been called in the first place (except that any modifications to @_ in the current subroutine are propagated to the other subroutine.) After the goto, not even caller() will be able to tell that this routine was called first.
Also, I realise that finding good examples is always a problem, but your example of where shift is dangerous isn't the fault of shift but of the logic of the test.
Using the correct test in the right place make it irrelavent which method is used to access the args I think?
sub fooge { die "fooge() needs two arguments\n" unless (@_ ==2); my ($foo, $bar) = (shift, shift); # or @_ are equally safe. # ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Shifty Politics
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 | |
by tadman (Prior) on Sep 11, 2002 at 01:36 UTC |