Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: variables not posting?

by ColtsFoot (Chaplain)
on May 03, 2001 at 10:43 UTC ( #77588=note: print w/ replies, xml ) Need Help??


in reply to variables not posting?

Always, always, always

#!/usr/bin/perl -w use strict;
Then USEFUL error messages are output
I think the following modified code may help
#!/usr/bin/perl -w use strict; use CGI::Carp qw(fatalsToBrowser); read (STDIN,my($temp), $ENV{'CONTENT_LENGTH'}); my (@pairs) =split(/&/,$temp); my($item) = ""; my %fields; foreach $item(@pairs) { my($key,$content) =split (/=/, $item, 2); $content=~tr/+/ /; $content=~s/%(..)/pack("c",hex($1))/ge; $fields{$key}=$content; } print "Content-type: text/html\n\n"; print "<HTML>\n"; print "<HEAD>\n"; print "<TITLE>This is a test of the stuffy perl network</TITLE>\n"; print "</HEAD>\n"; print "<BODY>\n"; print "$fields{tool}\n"; print "$fields{month}\n"; print "$fields{date}, $fields{month}\n"; print "</BODY>\n</HTML>";
Note the declaration of my %fields before the loop
Hope this helps


Comment on Re: variables not posting?
Select or Download Code
Re: Re: variables not posting?
by stuffy (Monk) on May 03, 2001 at 11:19 UTC
    That did help, thanks. I was wondering if somemonk could explaine why that worked, and why I needed to do that. Stuffy
      When you declare %fields inside the scope of the foreach $item (@pairs) loop with my, its contents are private to that loop. Then you try to access %fields after the loop, but it doesn't contain anything since you're outside the closing bracket (scope) of the for loop.

      -w and use strict tell of such errors.

      With your my declaration in the foreach loop you declared the hash locally.
      So the values you put into it weren't known outside.

      With using strict something like this can't happen because perl will give you an error.

      Have a look here for something more on my.
      You can also do a Super Search

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2014-09-20 21:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (163 votes), past polls