in reply to Missing Something
This four line chunk could be reduced into something like this:my($day,$month,$year) = (localtime)[3,4,5]; $month = $month + 1; $year = $year + 1900; my $date = "$month\/$day\/$year";
sprintf allows you to convert a list of items into a string, with formatting. It's a little hairy to use at first, but with a little practice it comes in quite handy. join() allows you to put things together on the double, but doesn't offer much flexibility.my (@time) = (localtime)[4,3,5]; my ($date) = sprintf ("%d/%02d/%02d", $time[0]+1900, $time[1]+1, + $time[2]); # Or if you don't care about formatting: my ($date) = join ('/', $time[0]+1900, $time[1]+1, $time[2]); # Or if you want to combine with your print, which would # avoid having to declare $date: printf GRAVE ("# consigned to the graveyard on %d/%d/%d\n", $date[0]+1900, $date[1]+1, $date[2]);
You will notice here that you are taking something from one array (<FILE>) and putting it into another (@output). Why not do it in one shot? @output = <FILE>; BTW, it would seem that your program inserts things into the GRAVE double-spaced. You're not removing the "\n" from the input stream FILE, so it's still there when you go and write into GRAVE with "$line\n"...while(<FILE>) { push @output, $_; }
|
|---|