Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm embarrassed to say I've been working w/PERL as a secondary tool for about 2 yrs. and don't know all about advanced (intermediate even) data strucs. All I know is that when I use cgi-lib.pl, I can get at my HTML text items by refing $in{'NAME'} Being the lazy programmer that I am, I was wondering if there was a slick way to automatically assign all these "in" cgi fields to common scalars easily, e.g. if I had a form containing HTML form text items NAME, ADDR then have $NAME and $ADDR vars auto style, instead of having to type $in{'NAME'} and in{'ADDR'} Thanks a mil, Rob

Replies are listed 'Best First'.
Re: cgi-lib.pl question
by davorg (Chancellor) on Jul 01, 2000 at 14:26 UTC

    Well, you'd need to be running this code without use strict or -w because it goes against all kinds of best practices (symbolic refs, undeclared vars), but you could do someting like this...

    foreach (keys %in) { $$_ = in{$_}; }

    But I think that all in all that is a very bad idea.

    If you were using CGI.pm instead of cgi-lib.pl you could use the import_names function which does something similar.

    Of course, if it's just the amount of typing that you're concerned about you can save two keystrokes on each hash element by typing $in{NAME} instead of $in{'NAME'}.

    --
    <http://www.dave.org.uk>

    European Perl Conference - Sept 22/24 2000
    <http://www.yapc.org/Europe/>
Re: cgi-lib.pl question
by merlyn (Sage) on Jul 01, 2000 at 20:48 UTC
      merlyn has the answers, as always. But just to make things a bit more easier for you, the simple way to get started on your transition from cgi-lib.pl to CGI.pm, is to use the compatibility mode. For instance:
      use CGI; CGI::ReadParse(*in);
      Voilá! You have your good ol' %in...

      #!/home/bbq/bin/perl
      # Trust no1!
Re: cgi-lib.pl question
by prodevel (Scribe) on Jul 02, 2000 at 16:40 UTC
    You guys are rock stars and I am most certainly humbled. If ever any native Oracle questions, i.e. non-DBI arise, I am definitely able to help. All areas including SQL, PL/SQL and DBA/Architechture issues, I would be most happy to oblige. Many thanks