[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Form Calculations



At 18:43 12/29/96, Robert Callaghan wrote:
>Many thanks to the list members who helped me with the basics of setting
>the execution permissions on my CGIs.

>    "What Size?",
>    popup_menu(-name=>'size',
>               -values=>['100.00','200.00','300.00'],
>-labels=>{'100.00'=>'Small','200.00'=>'Medium','300.00'=>'Large'
>}),

>if (param()) {
>    print
>        "Your name is: ",em(param('name')),
>        p,
>        "The keywords are: ",em(join(", ",param('words'))),
>        p,
>        "Your price for the above order is:
>",em(param('quantity')*(param('size'))),
>        hr;
>}

>The calculation works great but I want to put a "$" sign after "Your price
>for the above order is:"
>the script is not happy with a "Your price for the above order is: $",em...
>Probably something to do with the
>fact that "$" is used for variables.
>
>also I wanted to put ".00" after the price and the script seems to
>trunciate to a real number.

To print a character like @, $, %, etc. as non-interpolated, do one of the
following:
1.)  Use single quotes
2.)  Use the q operator  (see blue camel book, p. 41)
3.)  Escape character with \

Examples:
1.)  print 'Your price for the above order is: $'
2.)  print q"Your price for the above order is: $"
3.)  print "Your price for the above order is: \$"

As for the .00, use printf instead of print.  Example:

printf "Your price for the above order is:
\$<EM>%0.2f</EM>",(param('quantity')*(param('size')));

#========================================================================
I was going 70 miles an hour and got stopped by a cop who said, "Do
you know the speed limit is 55 miles per hour?"  "Yes, officer, but
I wasn't going to be out that long..."

        --Steven Wright

Chris Nandor                                              pudge@pobox.com
PGP Key 0xB76E72AD                                      http://pudge.net/