in reply to Getting hash of CGI variables
$params = $CGI->Vars; puts a hash reference in $params. The next line of the CGI.pm POD gives the example of dereferencing an example 'key' contained in the hash. $params->{'address'} is only an example of how easy it is to read a param value after you've loaded it into an anonymous hash. The author could just as easily have said $params->{'example_key'}.
Your line that says %params = $CGI->Vars; is wrong, because you're attempting to assign a hash REFERENCE to an actual named hash, rather than to a scalar (scalars hold references). You could modify that line to this:
That dereferences the anonymous hash and assigns it to a real hash, but it doesn't really gain you anything except perhaps one level less of abstraction. And if you do that, you can no longer say $params->{'address'}. You would have to remove the dereferencing operator (->), as in "$params{'address'}".%params = %{$CGI->Vars};
You probably should have a look at perlreftut, perllol, and perlref to gain a stronger working knowledge of how references work. Then it should all come together for you.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Getting hash of CGI variables
by Lori713 (Pilgrim) on Jan 22, 2004 at 20:59 UTC | |
by davido (Cardinal) on Jan 22, 2004 at 22:46 UTC |