Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Template toolkit Adding Values to Variable

by ahmad (Hermit)
on Mar 01, 2010 at 12:31 UTC ( [id://825896]=note: print w/replies, xml ) Need Help??


in reply to Template toolkit Adding Values to Variable

I am not sure if what you wrote would actually work or not, To my knowledge ... Template Toolkit foreach loops should be written as  [% FOREACH x IN  shopping %] Then you can use x.key to do what you want.

As I know Template Toolkit doesn't accept +=

Replies are listed 'Best First'.
Re^2: Template toolkit Adding Values to Variable
by seekperlwisdom (Acolyte) on Mar 01, 2010 at 12:37 UTC

    Code runs fine. it depend on the variable coming from the script. It is hash which i am using, if it is array then your given method is applied.

    thanks

      Where did you get this idea from?

      it works with a hash just like it works with arrays

      Anyway I have tried it and it works fine for me.

      [% totalprice = 900 %] [% FOREACH x IN shopping %] [% modelname = x.key %][% information = x.value %] [% MAKE_NAME = information.MAKE %] Quantity: [% information.QTY %] x [% information.PRICE %]<br/> [% ff = information.PRICE * information.QTY %] PRICE = [% ff %]<br/> [% totalprice = totalprice + ff %] [% totalprice %]#print out 1000 <hr/> [% END %] [% totalprice %]<----- 3 -------->

      It prints out 1000 as the final number not 900

        Thank you very much, it has solved all the problem, where as the hash and array are concerned i was just following the book and thinking accordingly. but again thanks for help me out.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://825896]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2024-04-19 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found