Ok.. Some people will think is obvious and stupid, but others newbies like myself might find it interesting. Earlier this week, I learned something new looking at some code in the Camal book on how to get the date using localtime. It uses an anonymous array (??correct term??)of the days of the week to return the day based on the index return by localtime.
So trying this technique out myself i create the one lined roman numeral converter!!
#!/usr/bin/perl -w # pass a number 1..10 to the program print scalar(("I","II","III","IV","V","VI","VII", "VIII","IX","X")[(shift)-1]);
Ok.. Stupid, but cool
zzspectrez
UPDATE:
This can be reduced further following a suggestion from Fastolfe.
print [qw/ I II III IV V VI VII VIII IX X /]->[shift()-1]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Simple but cool.. Roman Numerals (useless facts)
by extremely (Priest) on Nov 16, 2000 at 10:48 UTC | |
|
Re: Simple but cool.. Roman Numerals
by Beatnik (Parson) on Jan 17, 2001 at 03:23 UTC |