in reply to problem with form value (using cgi.pm)

You've shown how you print the form, but not what you do with the values you get. Somewhere, Perl is converting the strings to numbers. '/' is not a part of a number string, so that is where Perl quits trying.

It is perilous, but you could eval the string to get the division done. Perilous in case some rascal gets you to eval "system '/bin/rm', '-rf', $ENV{HOME};". You could also look at Math::Expr, which is perhaps safer.

After Compline,
Zaxo

  • Comment on Re: problem with form value (using cgi.pm)

Replies are listed 'Best First'.
Re: Re: problem with form value (using cgi.pm)
by MCS (Monk) on Feb 16, 2004 at 13:38 UTC

    I've shown how I print the values because that's where I'm having the problems. If I delete the default and type in the correct value (say "1 1/2") It works fine. However, when it prints the form, instead of printing the actual value of $ingredientAoH[$i]{qty}, it just prints the first number before a space or a slash. I've verified that $ingredientAoH[$i]{qty} contains the correct value because of the extra print statement in there.

    Oh and I don't want to evaluate the expression because I most recipes have things like 1/2 tsp salt... not 0.5 tsp salt. The only thing I can think of is that "-default=>"$ingredientAoH[$i]{qty}"" converts the string into a number. (which I don't want to do)