home *** CD-ROM | disk | FTP | other *** search
- # Perl version of Head.
- # Usage : head [-#] 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;
- }
-
- # For each file specified.
- foreach (<@ARGV>)
- {
- # Print the filename.
- print "\n--- ".$_." ---\n\n";
-
- # Print the first few lines of the file.
- open($input, $_);
- for ($i=0; $i<$lines; ++$i)
- {
- # If not past the eof.
- if ($line = <$input>)
- {
- print $line;
- }
- else
- {
- $i = $lines;
- }
- }
- close($input);
- }
-