in reply to Simulating UNIX's "tail" in core Perl

For Part 1 try the following snippet which calls the unix tail function:
system("tail -10 inputFile.txt >> outputFile.txt"); open <FILE, "</path/to/outputFile.txt"> or die "can't open file: $!\n" +; #do whatever here close FILE or die "can't close file $!\n";

In general, I do rely on calling Unix command line utilities for tools that I don't want to reinvent. I don't work on PC so much, so I'm not familiar with the situation there.

A 'pure' Perl implementation might involve counting all the lines in a file and then using the count to generate a new file which you would then process. This is more a Part 2ish approach. So for Part 2, try something like the following:

@input = <FILE>; $i = 0; foreach ($line (@input)) { $i++; if ($i >= 1034 || $i <= 1047) { #process here } } close FILE or die "can't close file: $!\n";

To count all the lines, just count your way through the foreach loop and use the final $i value as the number of lines in your file. This should help, I hope.

Have a look at chapters 8 and 9 of the Perl Cookbook - I just noticed a simple and elegant way of doing the line counting there. You might also try working with this PerlMonks node: Parsing a file one line at a time. I found this one to be quite helpful for this type of problem in general.

Good luck!

MadraghRua
yet another biologist hacking perl....