in reply to Re: Re: what does shift do?
in thread what does shift do?
sub greet { my $name = shift; print "Hello, $name\n"; } greet('dev2000');
In mod_perl, with Apache::Registry, your script is cached in a sub, and that sub gets the Apache object as its argument. You could of course write this:
But it's easier to have a named variable for that, especially when you use other subs and your @_ gets overwritten.$_[0]->send_http_header('text/plain'); $_[0]->print("mod_perl rules!\n");
is wrapped in a sub so it can be cached:my $r = shift; ...
And suddenly, it all makes sense.package Some::URL::Based::Package::Name;use Apache qw(exit);sub handle +r { #line 1 script.pl my $r = shift; ... }
- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.
|
|---|