I have an array and I would like to print the last few elements (most recent) to the screen. I have put together the following code to make this happen:
open (FILE, "$record") or die 'can\'t open record page: $!';
my @record =<FILE>;
close FILE;
my @record = reverse @record;
my @record1 = ($record[0], $record[1], $record[2], $record[3], $re
+cord[4], $record[5], $record[6], $record[7], $record[8], $record[9]);
+
my $record1 = join "<br>", @record1;
($record1 is then used in conjunction with HTML::Template.)
This is obviously not very perl so I thought I'd get some input from anyone kind enough to help me as to the alternatives I might have used to do the same thing.
One of the things I did try was the following:
@record = reverse @record;
my @record1;
my $count = 0;
while (($count < 5) && (my $line = @record)) {
push (@record1, $line);
$count += 1;
}
print "@record1";
This produced some very odd results so it's obvious that just as in the "Hitchhiker's Guide" I don't understand the question I asked! If someone does and could explain, that would be great.
Thanks very much.