in reply to Question, New To Hashes

This is how I would do it:
#!/usr/bin/perl use warnings; use strict; use Date::Manip qw(ParseDate); my @years = (2004..2008); sub find_year { my ($date) = @_; for my $year (@years) { my $date = ParseDate("$date $year"); return $year if $date; } return undef; } my @dates = ("Thu Sep 18", "Wed Sep 7"); for (@dates) { my $year = find_year($_); print "$_ => " . (defined($year) ? $year : "not found" ) . "\n"; }

Replies are listed 'Best First'.
Re^2: Question, New To Hashes
by walkingthecow (Friar) on Sep 19, 2008 at 16:29 UTC
    Thank you both! The first gave me a better idea of how to deal with hashes, and the second reply really helped me put the code into a subrouting. Again, thank you guys very much!