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:

$_[0]->send_http_header('text/plain'); $_[0]->print("mod_perl rules!\n");
But it's easier to have a named variable for that, especially when you use other subs and your @_ gets overwritten.

Back to the point, your script:
my $r = shift; ...
is wrapped in a sub so it can be cached:
package Some::URL::Based::Package::Name;use Apache qw(exit);sub handle +r { #line 1 script.pl my $r = shift; ... }
And suddenly, it all makes sense.

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.