Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dereferencing CGI->param 1

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
I am having trouble dereferencing the CGI->param vars

If I do this
Code:
 print "$cgi->param('name')";
I get
CGI=HASH(0x2155b8)->param('name')
if i do this
Code:
 print "$$cgi->param('name')";
I get
Not a SCALAR reference
if i do this
Code:
 print "\$cgi->param('name')";
I get
$cgi->param('name')

Now I know if I use concatination it will work but that's a real pain as this is a snippet from the massive long line of code as it is, without having to do
Code:
 "my text " . $cgi->param('varname') . " more stuff " . $cgi->param('varname') . " and more stuff" . $cgi->param('varname')
etc.. etc...

is there no way to get to the text value of the $cgi->param() object easily?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
When interpolating inside the quotes, perl won't recognise the -> operator, which means that the short answer is that no, you can't get at it easily. If you're using the variables a number of times, it might help to create variables to hold each of the parameters so that you can just put ordinary scalars into the string. Alternatively, you could use the CGI's Vars method to get the values into a hash, which you can then use directly inside the quotes.
 
not what i wanted to hear - lol, oh well, I guess concatination it is.

I see no point in creating vars to hold data already being held in memory, shame, would have made my life easier if you could get access within quotes!

thanks for the reply.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
For me, it would depend on how often I was likely to be using the variables in question. For a once-off, I wouldn't generally bother creating seperate variables. But if they were being used a few times, the amount of extra memory required is pretty minor compared to the boost to readability and maintainability of the code. That's my opinion anyway.
 
well that's me always trying to be clever and end up shooting myself in the foot!

PERL may have many ways to skin the cat, but it's always me who ends up red raw!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top