Erik W wrote:
> Hi guys,
> 
> Is it a way to pass the reference of an object to
> subroutine?
> Maybe I am trying to do something stupid and
> unnecessary here, but I would like to know if it is
> possible, how to do it? Why is it stupid? Is there a better way? 
> Thanks a lot! 
> 
> Here is the scripts:
> 
> $CGI=new CGI;
> test(\$CGI);
>  sub test {
>       my ($CGI)[EMAIL PROTECTED];
> print $CGI->header(),
> $cgi->start_html(),
> "test!",
>       print   $cgi->end_html;
>     }
> 
> I got an error message for this like
> "Can't call method "header" on unblessed reference at test.pl line 6.

An object *is* a reference, so just pass $CGI, and not \$CGI to test.

If you pass it as \$CGI, you have to dereference it as:

   print $$CGI->header,   # note extra $

But that isn't necessary.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to