> -----Original Message-----
> From: Gunnar Koppel [mailto:[EMAIL PROTECTED] 
> Sent: Monday, August 02, 2004 1:21 PM
> To: [EMAIL PROTECTED]
> Subject: [mp1]: different output under perlrun and CGI
> 
> 
> Terr!
> 
> I got some differencies between using script under CGI and
> Apache::PerlRun what i don't understand is that mandatory.
> 
> I am not an expert, so i try just to describe my situation.
> 
> I have an CGI-script with following sub:
> 
> sub PHeader {
> $_[0]
> ? print $q->header(-type=>"text/plain; $char",-cookie=>'')
> : print $q->header(-type=>"text/html; $char",-cookie=>'');
> }
> 
> I call this sub mostly &PHeader and only if i need "Content-type:
> text/plain" i add a argument &PHeader(1), for example.
> 
> Under CGI it works fine, but under Apache::PerlRun has @_ a value (for
> example "Apache::PerlRun=HASH(0x81ea01c) SCALAR(0x821a2bc)", i don't
> know where and why it comes) and my PHeader does not understand that i
> need a HTML-header. When i call a sub like &PHeader() or PHeader, it
> works fine, so main program does not deliver any arguments.
> 

Gunnar:

I have to admit, I'm not familiar with the internals of PerlRun, but
my bet is your problem is related to the fact that calling a sub in the 
format "&subname" (without a null param list), is treated like
calling it as "&subname(@_)".


from the perlsub perl docs:
(http://www.perldoc.com/perl5.8.4/pod/perlsub.html#DESCRIPTION)

If a subroutine is called using the & form, the argument list is optional,
and if omitted, no @_ array is set up for the subroutine: the @_ array at
the time of the call is visible to subroutine instead. This is an efficiency
mechanism that new users may wish to avoid.

    &foo(1,2,3);        # pass three arguments
    foo(1,2,3);         # the same

    foo();              # pass a null list
    &foo();             # the same

    &foo;               # foo() get current args, like foo(@_) !!
    foo;                # like foo() IFF sub foo predeclared, else "foo"  

---------


Looking briefly at Apache/PerlRun.pm (mod_perl 1), 
I see sub_wrap is wrapping the script into a handler sub routine:

    my $sub = join(
                    '',
                    'package ',
                    $package,
                    ';use Apache qw(exit);',
                    'sub handler {',
                    $line,
                    $$code,
                    "\n}", # last line comment without newline?
                    );

And a handler gets passed $r (the apache request).

So, @_ is populated in your scripts "main" section, and is
being passed to your subroutine (because of the way you are
calling your subroutine).

In summary, if you want a null list passed to your sub, you probably
should explicidly send it a null list.


Hope this helps,
Mike

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html

Reply via email to