in reply to form parsing

Assuming your input is well-behaved, you might pop all of it into a hash with something as simple as

# updated -- davorg noticed that $-> ... should be $_=> my %input = map { $_=>$cgi->param($_) } $cgi->param();

Warning: this won't work if you have multiple fields with the same name (that returns a list, not a scalar, as this code assumes -- if this is an issue, it can be dealt with, but I'll assume the simple case). Alternately, you can use the backwards-compatbility ReadParse function:

CGI::ReadParse(); # input values now in hash named "%in"

Anyhow, once it's all into the hash, you can do a

foreach my $key (keys %input) { $input{$key} =~ tr/*//d; # or whatever makes sense }

HTH.

perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'

Replies are listed 'Best First'.
Re: Re: form parsing
by merlyn (Sage) on Oct 09, 2001 at 19:07 UTC
    my %input = map { $_->$cgi->param($_) } $cgi->param();
    can be written as:
    my %input = map { $_ => scalar $cgi->param($_) } $cgi->param();
    to fix the possible "multiple value" problem, for some version of "fix". (Your arrow was wrong, by the way.)
    foreach my $key (keys %input) { $input{$key} =~ tr/*//d; # or whatever makes sense }
    can be written as:
    tr/*//d for values %input;
    for recent versions of Perl.

    -- Randal L. Schwartz, Perl hacker