in reply to Drop Down Year List

$year will always be less than $year + 9, so your loop will not terminate. A proper way to write the loop is:
for (my $y = $year; $y <= $year + 9; $y++) { print "<option value = '$y'>$y</option>\n"; }
Of course someone will come around and show how l44+ he is because he knows another way to write the loop.

Oh, and as for showing it in an HTML page - I would have the user type in the (2 digit) year. Typing 2 characters is faster than using the mouse.

Replies are listed 'Best First'.
Re^2: Drop Down Year List
by Tanktalus (Canon) on Aug 21, 2009 at 02:20 UTC

    As long as you're looking for 1733+ code, I'll add this one. I'm not intending to slight your code - it looks fine. It also is very reminiscent of C (and thus C++, Java, etc.). Here is one that is more perlish insofaras it's more unique to Perl:

    for my $y ($year .. $year + 8) { # this is inclusive print "<option value = '$y'>$y</option>\n"; }
    Or, even more perlishly:
    print "<option value = '$_'>$_</option>\n" for $year .. $year + 8;
    I prefer the first one in this case - the print is too long, forcing the for off the side of the screen or, as I did, on to the next line. IMO, it breaks the flow. I often use these modifiers at the end of the line, but just feel this one is less desirable.

    As to typing the year: I understand why some people prefer the drop-down. But, for me, I wish those people would shut up. I'd prefer the typing, too.