> if (!$ARGV[0]){
> die("you've forgotten to enter the file name\n");
> }
> if (!$ARGV[1]) {
> $n = 9; # output 10 rows by default
> }
> else {
> $n = $ARGV[1]-1;
> }
what if the user enters, "script.pl 8 " ??? This wil try to open a file 8
and dump last 9 lines of it.
if( $#ARGV != 2){ print " usage.....";exit 1;}
unless ( -f $ARGV[0] ){ print " bad file name ";exit 1;}
$n = $ARGV[1]-1 || 9;
----- Original Message -----
From: "Mrtlc" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, January 10, 2003 11:52 PM
Subject: tail + count
> I wrote the following script as a windows tail + count function,
> but it's too slow if the input is huge, how can it be improved?
>
> if (!$ARGV[0]){
> die("you've forgotten to enter the file name\n");
> }
> if (!$ARGV[1]) {
> $n = 9; # output 10 rows by default
> }
> else {
> $n = $ARGV[1]-1;
> }
>
> open IN, "$ARGV[0]" or die;
>
> @_ = <IN>;
>
> foreach my $i(($#_-$n)..$#_){
> print $_[$i];
> }
>
> close IN;
>
> $i = $#_+1;
> printf "-------\nTotal # of rows: $i\n";
>
>
> Thanks,
> Stan L
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]