home *** CD-ROM | disk | FTP | other *** search
- # Perl version of tail.
- # Usage : tail [-#] file1 file2 ...
- #
-
- # Is the first argument a -# ?
- if (substr($ARGV[0], 0, 1) eq "-")
- {
- # Yes, so read it.
- $lines = -(shift);
- }
- else
- {
- # No, so default to ten lines.
- $lines = 10;
- }
-
- # We are working modulo $lines, so increment it.
- $lines++;
-
- # For each file specified.
- foreach (<@ARGV>)
- {
- # Print the filename.
- print "\n--- ".$_." ---\n\n";
-
- # Print the first few lines of the file.
- open($input, $_);
- $i = 0;
- while ($line[($i++) % $lines] = <$input>)
- {
- }
-
- if ($i < $lines)
- {
- for ($j=0; $j<$i; ++$j)
- {
- print $line[$j];
- }
- }
- else
- {
- for ($j=$i-$lines; $j<$i; ++$j)
- {
- print $line[$j % $lines];
- }
- }
- close($input);
- }
-