RE: fmpp-open digest, Vol 1 #26 - 2 msgs
"Asad Niazi" <[email protected]> Thu, 17 Jun 2004 12:24:21 +0500
| Newsgroups | gmane.comp.text.fmpp |
|---|---|
| Message-ID | <[email protected]> |
Thankyou very much once again for your help. You are very right, i was trying to save hash values in the sequence because thats the requirement for the project that the hierarchy of the structure be kept like this. Now i understood the concept of the "index" parameter in the @pp.add from the example you gave. I have read the documents quite intensively already and i am really sorry as the lack of examples sometimes really confuse me. But now when i read the explanation again after this email, i feel that it didnt need an example to explain, i should have understood it in the first place. Btw i am a pakistani student and am doing my masters here in germany currently. thanks once again for your help. Best Regards Asadullah Khan Niazi >Today's Topics: > > 1. help required regarding saving values in a sequence during a loop >(Asad Niazi) > 2. Re: help required regarding saving values in a sequence during a >loop (Daniel Dekany) > >--__--__-- > >Message: 1 >From: "Asad Niazi" <[email protected]> >To: [email protected] >Date: Wed, 16 Jun 2004 14:52:36 +0500 >Subject: [FMPP] help required regarding saving values in a sequence during >a loop >Reply-To: [email protected] > >Hello! >I have a problem regarding saving values in a sequence (using the add/set >fmpp pphash) during a loop (inside the <#list> ). I intended to increase >the >index by increasing the counter x e.g. index = x, where x is increasing in >every run of the loop. > >The actual problem is that i dont understand the difference of "add" and >"set" fmpp pphash when they are used to add values in a sequence. For your >help let me outline what i am trying to do: >e.g the Writable seqeunce will be NamedNumber >it will have 2 subelements or "keys"; "Name" and "Number" >they can store values for lot of "names" and "numbers" (which makes it a >sequence) > >What I have currently done is that i have tried different combinations of >"set" and "add" on this writable sequence. > ><@pp.add seq=NamedNumber index=x value={"Name": whatevervalue} /> > >should this work?? > >or should i use?? > ><@pp.set seq=NamedNumber index=x key="Name" value=whatevervalue /> > >somehow both of these are not working. As i told you before i am not very >clear with the difference of set and add pphashes and the use of index >parameter in them. >I am desperately looking for help in this matter. I ll be looking forward >to >your reply. Thanking in anticipation. > >Best Regards >Asadullah Khan Niazi > >_________________________________________________________________ >The new MSN 8: advanced junk mail protection and 2 months FREE* >http://join.msn.com/?page=features/junkmail > > > >--__--__-- > >Message: 2 >Date: Wed, 16 Jun 2004 18:12:02 +0200 >From: Daniel Dekany <[email protected]> >To: Asad Niazi <[email protected]> >Subject: Re: [FMPP] help required regarding saving values in a sequence >during a loop >Reply-To: [email protected] > >Wednesday, June 16, 2004, 11:52:36 AM, Asad Niazi wrote: > > > Hello! > > I have a problem regarding saving values in a sequence (using the >add/set > > fmpp pphash) during a loop (inside the <#list> ). I intended to increase >the > > index by increasing the counter x e.g. index = x, where x is increasing >in > > every run of the loop. > > > > The actual problem is that i dont understand the difference of "add" and > > "set" fmpp pphash when they are used to add values in a sequence. > >As the documentation says, "add" inserts a new item, while "set" >replaces an already existing item at the specified index. > > > For your help let me outline what i am trying to do: e.g the Writable > > seqeunce will be NamedNumber it will have 2 subelements or "keys"; > >Sequences has no "keys". Only hashes has keys. Sequences has indexes. > > > "Name" and "Number" they can store values for lot of "names" and > > "numbers" (which makes it a sequence) > > > > What I have currently done is that i have tried different combinations >of > > "set" and "add" on this writable sequence. > > > > <@pp.add seq=NamedNumber index=x value={"Name": whatevervalue} /> > > > > should this work?? > >Yes... as far as the variable values are correct, i.e. x is an integer >with correct value, etc. > > > or should i use?? > > > > <@pp.set seq=NamedNumber index=x key="Name" >value=whatevervalue /> > >It's surely bad, as sequences has no keys. > > > somehow both of these are not working. As i told you before i am not >very > > clear with the difference of set and add pphashes and the use of index > > parameter in them. > >It seems that the root of the problem that you don't understand what are >sequences and what's a hashes. You may should read the FreeMarker Manual >about this, if you didn't. Anyway... I try to explain it now. Both data >structure is a collection. They store multiple values of *any* type. >Now, to access (read/modify/delete/etc.) a value in a collection somehow >you must use the unique address of the value (unique in the collection). >In the case of hashes addresses are strings that are called keys. In the >case of sequences addresses are integer numbers that are called indices. >The indices has the restriction that they are continuos and always >starting from 0, so for example if the sequence length is 4, then the >available indexes are 0, 1, 2, 3 (so if you "pp.add" a value with index >2, then the the size will grow to 5, and the index of the values after 2 >will increase by 1). > >Now, in your case you just want to address words (the names) with an >integer index, so you don't need hashes at all (seems that you tried to >build a sequence of hash values... you can, but I guess you don't need >to). So what you want could work somehow like this: > > <#assign NamedNumber = pp.newWritableSequence()> > <@pp.add seq=NamedNumber value="Foo" /> > <@pp.add seq=NamedNumber value="Bar" /> > <@pp.add seq=NamedNumber value="Baaz" /> > Now test it: > <#list NamedNumber as n> > - ${n} > </#list> > ${NamedNumber[1]} > >(See the @pp.add documentation about the meaning of missing "index" >parameter.) And this outputs: > > Now test it: > - Foo > - Bar > - Baaz > Bar > >Of course, in the above template could be implemented without writable >sequences as well: > > <#assign NamedNumber = ["Foo", "Bar", "Baaz"]> > > > I am desperately looking for help in this matter. I ll be looking >forward to > > your reply. Thanking in anticipation. > >Well, *if* you didn't do it so till now, use the FMPP and the FreeMarker >Manual intensively... they are quite detailed, it's all described there. > > > Best Regards > > Asadullah Khan Niazi > >BTW, which country? > >-- >Best regards, > Daniel Dekany > > > > > >--__--__-- > >_______________________________________________ >fmpp-open mailing list >[email protected] >https://lists.sourceforge.net/lists/listinfo/fmpp-open > > >End of fmpp-open Digest _________________________________________________________________ Tired of spam? Get advanced junk mail protection with MSN 8. http://join.msn.com/?page=features/junkmail ------------------------------------------------------- This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND