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

Hi all, I'm new to perl, have a project for school to do (with perl, cgi and iptables :) and runnig out of time. I began writing it and immediately ran into problems. This is the script:
if ($ENV{'REQUEST_METHOD'} eq "GET") { $in = $ENV{'QUERY_STRING'}; } else { $in = <STDIN>; } @podatki = split (/&/, $in); foreach my $slot (@podatki) { %uporabnik = split (/=/,$slot); }
It's very basic, but @podatki and %uporabnik stay empty and I don't know why. I've followed instructions. $in contains something like this: "ime=Janez&vzdevek=Yanezh&Submit=Moving+on" when the script is called. Any ideas about solving this are wellcomed :)

Replies are listed 'Best First'.
Re: form processing problem
by merlyn (Sage) on Mar 24, 2005 at 15:43 UTC
Re: form processing problem
by brian_d_foy (Abbot) on Mar 24, 2005 at 15:50 UTC

    Rather than try to program all of the CGI stuff yourself, use the CGI module. It comes with Perl, does all the magic, and let's you focus on the real problem. :)

    --
    brian d foy <bdfoy@cpan.org>
Re: form processing problem
by manav (Scribe) on Mar 24, 2005 at 15:49 UTC
    Two ways.

    The first post shows you the way in which you import a subset of the symbols exported/exportable in CGI package into the current package namespace. Second method, the object-oriented method, in which you work with a reference to an object of CGI
    use strict ; use warnings ; use CGI ; my $query = new CGI ; my $ime = $query->param('ime'); # will get Janez my $vzdevek = $query->param('vzdevek'); # will get Yanezh


    Manav
      Second method, the object-oriented method, in which you work with a reference to an object of CGI
      And I've never really seen an advantage to that, except to make CGI programming look harder than it needs to look for the beginning programmer.

      Apparently, Lincoln agrees. The latest releases of CGI.pm documentation emphasize the imported version, rather than the object version. Makes the manpage look a whole lot cleaner.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

        Object oriented approach makes programmers who are conversed with C++ think that they know what's going on... ;)


        Seriously, the given example notwithstanding, I've seen lots of code with
        use CGI qw/:standard/ ; print redirect('http://www.nowhere.to.go') ;
        I mean, Isnt it useless to clutter up your namespace with imported symbols just to use next-to-nothing from it??


        Manav

        First off, when talking about general advantages of OO vs import-the-world (or import-what-you-need), I'm not sure that we could all agree on a single expert (possibly including Larry). And, even if we could, I'm not sure that Lincoln would necessarily be that expert ;-)

        Secondly, the CGI documentation still states:

        The examples in this document mainly use the object-oriented style.
        It's not entirely clear that Lincoln has a preference.

        Personally, I prefer the OO style to keep things clear in my head where things are coming from. But maybe that's just me. :-)