Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Popup Menu (CGI.pm) Question

Status
Not open for further replies.

rdyoll

Technical User
Aug 11, 2003
39
US
Hi, I've written a little script that generates a popup menu with the current and preceeding 29 years (a perpetual date-type select box) that I use in a form. It works fine, but my question is "Is there a better way to set up the array for the years?" Programatically, I'm sure there is a smarter, shorter way. Can anyone help? Below is the script

###########################################################

#!/usr/bin/perl

use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);

my $q = CGI->new();
my $date = &set_year;
my @yrs = ($date,$date-1,$date-2,$date-3,$date-4,$date-5,
$date-6,$date-7,$date-8,$date-9,$date-10,$date-11,$date-12,
$date-13,,$date-14,$date-15,$date-16,$date-17,$date-18,$date-19,
$date-20,$date-21,$date-22,$date-23,$date-24,$date-25,$date-26,
$date-27,$date-28,$date-29,$date-30);

print $q->header,
$q->start_html,
$q->start_form,
$q->popup_menu( -name => 'year',
-values => \@yrs ),
$q->end_form,
$q->end_html;

sub set_year {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year += 1900;
$date = $year;
}
 
A short for loop should work:
Code:
my @yrs;
push @yrs, $date-$_ for(0..30);

________________________________________
Andrew - Perl Monkey
 
EXCELLENT! I knew there was an easier way. Works Awesome.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top