Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: List Context Warn

by stevieb (Canon)
on Sep 02, 2015 at 18:36 UTC ( [id://1140828]=note: print w/replies, xml ) Need Help??


in reply to List Context Warn

You can disable that warning by using that variable at least once (eg: print $CGI::LIST_CONTEXT_WARN;), or by using no warnings 'once';, but I'd *highly* recommend against the latter (unless it is used within a limited scope, as pointed out by ikegami below).

There was a vulnerability found in CGI retrieving a list from the param() method, and a new multi_param() method was created to get around it. From perldoc CGI:

"Warning - calling param() in list context can lead to vulnerabilities if you do not sanitise user input as it is possible to inject other param keys and values into your code. This is why the multi_param() method exists, to make it clear that a list is being returned, note that param() can still be called in list context and will return a list for back compatibility."

...and...

"If you call param() in list context with an argument a warning will be raised by CGI.pm, you can disable this warning by setting $CGI::LIST_CONTEXT_WARN to 0 or by using the multi_param() method instead"

So instead of dealing with the warnings of "only once" and having to understand how to protect against the vulnerabilities, get rid of the assignment line ($CGI::LIST_CONTEXT_WARN = 0;) that's causing the warning, use the recommended multi_param() for data you know is a list, and let CGI list warning output tell you when you've got a call in list context with the param() method so you can replace it with the newer multi_param() one.

-stevieb

Replies are listed 'Best First'.
Re^2: List Context Warn
by ikegami (Patriarch) on Sep 02, 2015 at 18:43 UTC

    I strongly disagree. I highly recommend no warnings 'once'; rather than misleading the reader by using print to do the same thing. Just be sure to limit the scope in which you disable the warning.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1140828]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-19 13:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found