CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
I'm looking for a way to avoid some repetition.

 



DrZed
User

Jun 23, 2000, 5:00 PM

Post #1 of 2 (322 views)
I'm looking for a way to avoid some repetition. Can't Post

Right now, because of the way I have things structured, I need to define a value as follows:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

....
options =>
[{
VALUE => "-12",
selected => (($cookie{'TIMEZONE'} == -12) ? ("SELECTED") : ("")),
text => (&date_as_text(time()+3600*(-12-$cookie{'TIMEZONE'}),'DATE'))
},{
VALUE => "-11",
selected => (($cookie{'TIMEZONE'} == -11) ? ("SELECTED") : ("")),
text => (&date_as_text(time()+3600*(-11-$cookie{'TIMEZONE'}),'DATE'))
},{
VALUE => "-10",
selected => (($cookie{'TIMEZONE'} == -10) ? ("SELECTED") : ("")),
text => (&date_as_text(time()+3600*(-10-$cookie{'TIMEZONE'}),'DATE'))
....</pre><HR></BLOCKQUOTE>

with values ranging from -12 to 12.

I'm hoping that there is a less repetative way of doing this. Perhaps by using map.

I tried the following:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


options =>
map(
({
VALUE => "$_",
selected => (($cookie{'TIMEZONE'} == $_) ? ("SELECTED") : ("")),
text => (&date_as_text(time()+3600*($_-$cookie{'TIMEZONE'}),'DATE'))
}),(-12..12)),
</pre><HR></BLOCKQUOTE>

... it doesn't work, but it should give you an idea of what I'm looking for.

Dr. Zed


japhy
Enthusiast

Jun 25, 2000, 5:54 AM

Post #2 of 2 (322 views)
Re: I'm looking for a way to avoid some repetition. [In reply to] Can't Post

Zed, you were damn close. Smile Put the [ and ] around your map function:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


option => [
map (
# ...
)
]
</pre><HR></BLOCKQUOTE>

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives