Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

What namespace is CGI:ReadParse() using?

by Cody Pendant (Prior)
on Jul 01, 2002 at 02:12 UTC ( [id://178449]=perlquestion: print w/replies, xml ) Need Help??

Cody Pendant has asked for the wisdom of the Perl Monks concerning the following question:

I was just going over a script which uses the deprecated, non-OO form of getting the variables from CGI.pm, the one where you do CGI:ReadParse() and it puts everything into a hash called %in.

Leaving aside the "stop doing it that way" answers, how do I make my script valid using strict if it uses this hash -- it's not my hash, after all.
--

($_='jjjuuusssttt annootthheer pppeeerrrlll haaaccckkeer')=~y/a-z//s;print;

Replies are listed 'Best First'.
Re: What namespace is CGI:ReadParse() using?
by mattriff (Chaplain) on Jul 01, 2002 at 02:32 UTC
    I second theorbtwo's recommendation to use Vars(), but in quick testing it looks like you can declare a hash and pass a reference to it as an argument to ReadParse():
    my %vars; CGI::ReadParse(\%vars);
    I used %vars to illustrate it could have any name, but of course you could use %in if you needed for compatibility.

    UPDATE: And clintp is right on both counts, by the way. So, if you are going to use ReadParse() you are probably best off declaring our %in; and forgetting about it. But "there's more than one way to do it," and all of that. :)

    - Matt Riffle

Re: What namespace is CGI:ReadParse() using?
by clintp (Curate) on Jul 01, 2002 at 02:16 UTC
    Use the fully qualified name of the variable (%main::in) or declare the variable with our %in in your program. (Presumably it's using %main::in. Adjust accordingly otherwise.)
      So, the hash is in the main namespace? And what does one do to make code which uses it strict-proof -- I'm missing something obvious, aren't I?
      --
      ($_='jjjuuusssttt annootthheer pppeeerrrlll haaaccckkeer')=~y/a-z//s;print;
        The bog standard our %in; in main - or if you're using an older Perl, use vars qw(%in);

        Makeshifts last the longest.

Re: What namespace is CGI:ReadParse() using?
by theorbtwo (Prior) on Jul 01, 2002 at 02:19 UTC

    I'm not sure if this qualifies as a "stop doing it that way" but it seems that Vars is exactly what you want. To paraphrase the docs,

    use CGI ':cgi-lib'; %in = Vars;
    .

    Or, do an our %in at the top, or use %::in.


    We are using here a powerful strategy of synthesis: wishful thinking. -- The Wizard Book

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-20 02:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found