#!/bin/perl5 -w # $Id: crowd,v 1.1 1999/10/01 16:01:22 annis Exp $ # $Source: /u/annis/uw-unix/perltut/RCS/crowd,v $ use Getopt::Std; use strict; use vars qw/$opt_n $opt_o/; # usage() - print out the required usage of this program sub usage { print STDERR "crowd -n \n"; print STDERR "crowd -n <#> -o \n"; exit(1); } # getlines($nlines, $file) -- grabs $nlines lines from $file sub getlines { my ($nlines, $file) = @_; my @lines; open(FH, "< $file") or die "can't open $file: $!"; for (my $i = 0; $i < $nlines; $i++) { my $line = ; # Removes newline at end chomp $line; # Shoves a value on end of array push @lines, $line; } close(FH); return @lines; } # The infile will be left in @ARGV. getopt('n:o:'); # Die if they didn't tell us how many lines or an infile if (! $opt_n or $#ARGV < 0) { &usage; } my @lines = &getlines($opt_n, $ARGV[0]); if ($opt_o) { open(FH, "> $opt_o") or die "cannot open $opt_o: $!"; print FH "@lines\n"; close(FH); } else { print "@lines\n"; } # EOF