Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: map, grep, for, foreach

by mt2k (Hermit)
on Jun 06, 2002 at 05:00 UTC ( [id://172079] : note . print w/replies, xml ) Need Help??

in reply to map, grep, for, foreach

Okay I screwed that example up... Last line should say:

while (my($n,$v) = each %input) { print "$n: $v<br>"; }

It won't work the way I have it for 2 reasons: 1. I kinda threw a semi-colon in between the EXPR and the loop 2. You must show the loop first when initializing variables within the loop statement (in order to satisfy strict).

And okay, so the following code would work:

#!c:/perl/bin/perl -w use strict; use CGI 'Vars'; my %input = CGI::Vars; print "Content-type: text/html\n\n"; while (my($n,$v) = each %input) { print "$n: $v<br>"; }

Let's go to lala land and pretend could not do this. What would be the best alternative? (By the way, thanks. I have already modified my scripts to use this wonderful CGI::Vars ;))