How to implement Linux tail command in Perl
I have tried writing a Perl script to simulate Linux tail command - print last n lines from a file. This is one of the common interview questions in Perl. This can be extended to print selected lines of other Linux commands like head. It works perfectly fine. print "\nImplements linux tail command in perl \n\n"; $file = $ARGV[0]; $n = $ARGV[1]; open(FILE, $file); @arr = ; close(FILE); $length = scalar(@arr); $n = $length - $n; while($n<$length ) { print $arr[$n]; $n =$n + 1; } Comment below if you have a better option