I learn something about tell(), then abuse it.
I learned a new thing today, or remembered a forgotten one. I can use tell to affect the file handle that
It all started very simply. I was going too far in my answer to How do I add the elements of a file to a second one as columns using Perl?, a question I found by looking for the most down voted open questions without an accepted answer. As usual, I thought the answer would be easy. And, for the most part it was.
Then I wanted to make it even easier. I thought Perl might not be necessary at all when we have things like
tail and other command-line thingys. The problem was a header in one input file and no corresponding header in the other. How could I make
paste ignore the header?
I bet there's something that I'm missing, but I started working with the Perl Power Tools version of
paste. To fast forward through a file to get to the right starting point, I wanted to look at
$. to know when to stop, but that only works for the last read filehandle. To use it on another filehandle, I need to do something to to that handle without disturbing the data. tell was just the thing.
tell( $fh ) readline( $fh ) while $. < $starting_line - 1;
But, now I think that's also stupid because I didn't need the magic because I don't need to know the number of the currently read line:
readline( $fh ) foreach 1 .. $starting_line - 1;
As Perl gives, so Perl takes away (brain cells).