Bruce Perryman | 16 May 2006 17:27
Picon
Favicon

Is there a more efficient way to look up a list?

Hello. I hope that I explain this clearly enough.

Let's say I have the code 'BBB' stored in 'myCode' and the following list:

options=
[code:AAA,description:A1,text:A2,
 code:BBB,description:B1,text:B2,
 code:CCC,description:C1,text:C2,
 code:DDD,description:D1,text:D2]

I need to display the description of the code value that I have. What I currently do is the following:

                <#list options as x>
                 <#if (x.code?trim==mycode)> 
                    ${x.description?trim}
                 </#if>
                </#list>      

It seems to work. But is there a more efficient way to do this?

Thanks.                    

Love cheap thrills? Enjoy PC-to-Phone calls to 30+ countries for just 2¢/min with Yahoo! Messenger with Voice.
Daniel Dekany | 16 May 2006 20:27
Picon
Favicon

Re: Is there a more efficient way to look up a list?

Tuesday, May 16, 2006, 5:27:22 PM, Bruce Perryman wrote:

> Hello. I hope that I explain this clearly enough.
>
> Let's say I have the code 'BBB' stored in 'myCode' and the following list:
>
> options=
> [code:AAA,description:A1,text:A2,
>  code:BBB,description:B1,text:B2,
>  code:CCC,description:C1,text:C2,
>  code:DDD,description:D1,text:D2]
>
> I need to display the description of the code value that I have.
> What I currently do is the following:
>
>                 <#list options as x> 
>                  <#if (x.code?trim==mycode)>  
>                     ${x.description?trim}
>                  </#if>
>                  </#list>       
>
> It seems to work. But is there a more efficient way to do this?

What about using a map where the key is the code for the options?

Also, if the <#list> solution remains, put a <#break> after the
${x.description?trim}. Unless, there can be more list items with the
same code.

--

-- 
Best regards,
 Daniel Dekany

-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
Bruce Perryman | 17 May 2006 17:41
Picon
Favicon

Re: Is there a more efficient way to look up a list?

Thanks for your help and great suggestions.

For the <#break> should that go after the ${x.description?trim} or the </#if> or does it matter?

Thanks again.

Daniel Dekany <ddekany <at> freemail.hu> wrote:

Tuesday, May 16, 2006, 5:27:22 PM, Bruce Perryman wrote:

> Hello. I hope that I explain this clearly enough.
>
> Let's say I have the code 'BBB' stored in 'myCode' and the following list:
>
> options=
> [code:AAA,description:A1,text:A2,
> �code:BBB,description:B1,text:B2,
> �code:CCC,description:C1,text:C2,
> �code:DDD,description:D1,text:D2]
>
> I need to display the description of the code value that I have.
> What I currently do is the following:
>
> ��� ��� ��� ��� <#list options as x>
> ��� ��� ��� ���� <#if (x.code?trim==mycode)>�
> ��� ��� ��� ������� ${x.description?trim}
> ��� ��� ��� �� �
> ��� ��� ��� ��� ������
>
> It seems to work. But is there a more efficient way to do this?

What about using a map where the key is the code for the options?

Also, if the <#list> solution remains, put a <#break> after the
${x.description?trim}. Unless, there can be more list items with the
same code.

--
Best regards,
Daniel Dekany



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid
Daniel Dekany | 17 May 2006 18:47
Picon
Favicon

Re: Is there a more efficient way to look up a list?

Wednesday, May 17, 2006, 5:41:11 PM, Bruce Perryman wrote:

> Thanks for your help and great suggestions.
>
> For the <#break> should that go after the ${x.description?trim} or
> the </#if> or does it matter?

After the ${x.description?trim}, but before the </#if>. The <#break>
directive, when executed, exits from the <#list> loop. Like if you
were reached the end of the list, you see.

> Thanks again.

--

-- 
Best regards,
 Daniel Dekany

-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
Bruce Perryman | 31 May 2006 18:00
Picon
Favicon

Dealing with reserved names

Hi,

Quick, simple question. I have a hash which contains the name 'default' as one of the keys. When I attempt to display it's value, there's a problem.

${level1.level2.default}

Is there a way to escape this, or must the key name be changed?

Thanks

How low will we go? Check out Yahoo! Messenger’s low PC-to-Phone call rates.
<div>
<p>Hi,<br><br>Quick, simple question. I have a hash which contains the name 'default' as one of the keys. When I attempt to display it's value, there's a problem.<br><br>${level1.level2.default}<br><br>Is there a way to escape this, or must the key name be changed?<br><br>Thanks<br></p>
<p>
		</p>How low will we go? Check out Yahoo! Messenger&#146;s low <a href="http://us.rd.yahoo.com/mail_us/taglines/postman8/*http://us.rd.yahoo.com/evt=39663/*http://voice.yahoo.com"> PC-to-Phone call rates.</a>
</div>
_______________________________________________
fmpp-open mailing list
fmpp-open <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fmpp-open
Daniel Dekany | 1 Jun 2006 00:12
Picon
Favicon

Re: Dealing with reserved names

Wednesday, May 31, 2006, 6:00:11 PM, Bruce Perryman wrote:

> Hi,
> 
> Quick, simple question. I have a hash which contains the name
> 'default' as one of the keys. When I attempt to display it's value,
> there's a problem.
> 
> ${level1.level2.default}
> 
> Is there a way to escape this, or must the key name be changed?
> 
> Thanks

Why is the "default" key already used for something? From what data
source does the hash come from?

--

-- 
Best regards,
 Daniel Dekany

Gmane