ok, i'm not 100% sure what you're doing here..
the object CGI.pm returns is a hash reference... so what your'e doing here
is passing a reference to a hashreference.
why?
secondly, you're prototyping your subroutine... altho it has it's use in
some cases, most of the time this is NOT what you want
prototyping in perl is not like prototyping in other languages, and is prone
to break your program if you're not 100% sure of what your'e doing.
from what i'm seeing, the followign code might do what you want:
ispresent( $req, $param )
sub ispresent {
my $q = shift;
my $p = shift;
defined ( $q->{ $p } ) ? return 1 : return undef
}
basicly, just testing the definedness of a certain param....
you could easily pull taht out of a sub, but hey, timtowtdi
if you have any more questions about references, i suggest you read the
reference tutorial at http://japh.nu first
regards,
Jos
----- Original Message -----
From: "David Simcik" <[EMAIL PROTECTED]>
To: "Perl Beginners" <[EMAIL PROTECTED]>
Sent: Thursday, August 16, 2001 6:32 PM
Subject: Passing Scalar Reference to Subroutine
> Newbie question here...
>
> I've created a CGI.pm object and want to pass its reference to a function.
> It keeps on puking though, returning this message:
>
> Type of arg 1 to main::isPresent must be scalar (not single ref
constructor)
> at C:\src\Orion\cgi-bin\share.pl line 45, near "$user)"
>
> Basically, I'd like to treat the $req CGI.pm object as just that in the
> function call isPresent(). Maybe not the best use of a reference, but I'm
> hellbent on figuring out this reference thing first! ;-)
>
>
> Here's the offending source (I've left out code for brevity). Please note
> that I have set this function up in prototype form (mostly for
posteirity):
>
> sub isPresent(\$$);
>
> our $req = new CGI();
>
> if(!isPresent(\$req, $user))
> {
>
> print "User not present\n";
> }
> elsif (!isPresent(\$req, $pass))
> {
>
> print "Password not present\n";
> }
> elsif (!isPresent(\$req, $agreed))
> {
>
> print "Agreement not present\n";
> }
>
> sub isPresent(\$$)
> {
>
> my $qref = shift;
> my $paramname = shift;
> my $query = $$qref;
>
> if($query->param($paramname) =~/""/ || !defined
($query->param($paramname))
> {
> #return;
> }
>
> #otherwise...
> return 1;
> }
>
>
>
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]