glad you got it working! I'll continue where i was going above with some general hints/guidelines:
- Try to keep output statements separate from the logic. For example, instead of alternating code & print statements, just do a single print at the bottom of the 'for' loop:
printf 'Certification is %s on %02d % 02d %d<p><HR>',
$certification, $month, $day, $year;
Kind of trivial here, but what this will do is make the output much easier to understand and modify in the future. (For larger future projects, be sure to investigate things like Template::Toolkit or HTML::Template)
- Be aware of the scope of your variables. In this case, $i, $certification, $number, $month, $day, and $year are all only used inside the for loop. so instead of having the 'my' declaration globally, can just do it in the for loop (this makes it very clear that these variables only exist/have meaning just right here):
for (my $i=1; $i<=$lines; $i++) {
my $certification = shift(@data);
my $number = shift (@data);
my $month = $mon [$number-1];
my $day = shift (@data);
my $year = shift(@data);
# printf ....
}
- this is a great one for TMTOWTDI .. first off, note that the for ($i=1; $i<=$lines; $i++) construct is very "c-ish" and there are usually 'better' ways to write it in perl.. For example (there's no "right" way here--just a bunch of different ways) the $i is unnecessary in this case:
while(@data){
...
}
Note that it's still dependent on the file format being sets of 4 lines ..
- One of perl's great strength's is CPAN -- so always remember that if the answer to "is it likely someone else has had to do this?" is "yes" or "most certainly", head to http://search.cpan.org. For example, Date::Calc (there are other Date modules as well) has a Month_to_Text function that does exactly what you need, thus eliminating the need for @mon or %mon or something like that.
use Date::Calc qw/Month_to_Text/;
while(@data){
...
my $number = shift (@data);
my $month = Month_to_Text($number);
...
}