Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Some code

by aeshirey (Initiate)
on Apr 24, 2002 at 20:38 UTC ( #161783=note: print w/replies, xml ) Need Help??

in reply to use strict seems to hose my code

Thanks for your replies. I didn't post code initially because I didn't think people would appreciate me dumping the problem directly onto them. But here's the relevant code:

Immediately after the relevant beginning lines, I create three hashes I'll use. %INPUT is the one in question. I haven't got it far enough to know if the other two work. We all know %ENV, and %CFG has values from a config file I load.

my (%INPUT,%CFG,%ENV);

To clean up my "main" program, I dump off the initialization of %INPUT to a subroutine, which I call immediately after my variable declarations (save a few comments in between):

my ($buffer,$name,$value,@pairs,$pair); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { $name, $value) = split(/=/, $pair); $value =~ tr/+/ /; value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; $INPUT{$name} = $value; print "\$INPUT{$name} = $value<br>"; }

That last line was put in to help me see if any of the values are printed. I expected it to at least print "$INPUT{} = " (null for the actual values), but in fact, it didn't print anything.

Even if I put this code immediately after the above "my (...)" code, it still doesn't give me any output.

Replies are listed 'Best First'.
Re: Some code
by stephen (Priest) on Apr 24, 2002 at 21:15 UTC

    First, what you have there is one of the oldest bits of hand-recopied Perl code on the Internet. It's from the original by a nice fella named Steve Brenner. You should use CGI. See use CGI or die; for why.

    Next, %ENV is a global variable. Putting it in a my declaration will wipe it clean. Thus there will be no $ENV{'QUERY_STRING'}, no $ENV{'CONTENT_LENGTH'}, thus no $buffer, and thus no output. There's no need to try to localize %ENV; strict knows it's a global and won't yammer.

    Update: Never mind %ENV, $buffer is empty. Use CGI instead. :)


Re: Some code
by CukiMnstr (Deacon) on Apr 24, 2002 at 21:11 UTC
    Maybe you stripped more than what you had to to post your code here, but from what I can see,
    my ($buffer,$name,$value,@pairs,$pair); @pairs = split(/&/, $buffer);

    you are acting on an empty $buffer: the my declaration of $buffer 'initializes' it, so when you use split() to get the values from it, you are acting on an 'empty' variable. You might want to move that

    my ($buffer);
    a little higher on your script.

    Do you get any warnings that tell you you are acting on undefined data? try printing $buffer before and after the split(), because it might tell you the problem is there...

    Update: you say you don't even get 'empty' lines printed, which tells me you never run the for() loop... try to print() @pairs before entering the for()

    hope this helps,

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://161783]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2017-02-23 22:36 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (351 votes). Check out past polls.