in reply to globbed variable in parse cgi form - beyond me

Don't recreate CGI!
  • Comment on Re: globbed variable in parse cgi form - beyond me

Replies are listed 'Best First'.
Re^2: globbed variable in parse cgi form - beyond me
by Don Coyote (Hermit) on Jun 27, 2011 at 01:53 UTC

    thanks ikegami,

    it was not my intention to recreate cgi - i was just following the instructions as it were.

    Basically I need to be doing something along these lines then(see code), although the input element names are being returned where the values are not. yet...

    #! /usr/bin/perl -w use strict; use warnings; use CGI; use CGI::Carp qw(fatalsToBrowser), qw(warningsToBrowser); my ($webmaster, $user, $name, @names, $value, @values, $query); $query = CGI->new; $webmaster = "http\:\/\/www.mysite.com\/"; @names= $query->param; foreach $name(@names){ $value = $query->param('$name'); push(@values, $value); } print "Content-type: text/plain\r\n\r\n"; print "names @names \n\n"; print "values: @values \n\n"; exit(0);

      '$name' creates the 5 character string "$","n","a","m","e". Double-quoted strings interpolate, but no need for that either. Use ->param($name)

      May I also recommend that you don't declare your variables until you need them? No need to make their scope larger than needed.

      #! /usr/bin/perl -w use strict; use warnings; use CGI; use CGI::Carp qw( fatalsToBrowser warningsToBrowser ); my $query = CGI->new; my $webmaster = "http://www.mysite.com/"; my @names = $query->param; my @values; foreach my $name (@names) { my $value = $query->param($name); push(@values, $value); } print "Content-Type: text/plain\r\n\r\n"; print "names @names\n\n"; print "values: @values\n\n";
        Ikegami,

        Noted

        • scope - not declaring variables before scope required.
        • interpolation - I will have to watch for these syntax traps with this too
        • To remove the single quotes was going to be my next move. Though it is good to understand why so thanks for explaining that. Declaring variables in scope to be used is also something I will adhere to going forward.

          While this is my first CGI script and I do like to learn quicka nd easy, I prefer to understand what it is I'm being quick and easy about. Security always being foremost in my mind. The glob variable is not something I have covered in my reading yet. (getting there..!). So my question was related to trying to get a quick explanation for how to define the glob and subsequent referenced % to get the code to work so that I could digest the principles in due course.

          Of course I was directed back to the CGI module and rightly as it is designed to do what I need to do. The reson I have not been using CGI up till now is that:

          • I had no data being posted to process.
          • CGI.pm produces xhtml and I am writing in 4.01 strict currently

          So in a way I am keeping in scope of DTD.

          However I have realised I am suffering from a race condition. Making my first $million in webification vs buying various animals from the "Zoo".

          Anyone want to sponser a dingbat?