File tree Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ use constant EX_FAILURE => 1;
23
23
my $Program = basename($0 );
24
24
my ($VERSION ) = ' 1.3' ;
25
25
26
+ @ARGV = new_argv();
26
27
my %opt ;
27
28
unless (getopts(' n:' , \%opt )) {
28
29
warn " usage: $Program [-n count] [file ...]\n " ;
@@ -66,16 +67,16 @@ foreach my $file (@ARGV) {
66
67
}
67
68
print " ==> $file <==\n " ;
68
69
}
69
- tail_fh ($fh );
70
+ head_fh ($fh );
70
71
unless (close $fh ) {
71
72
warn " $Program : failed to close '$file ': $! \n " ;
72
73
$rc = EX_FAILURE;
73
74
}
74
75
}
75
- tail_fh (*STDIN ) unless @ARGV ;
76
+ head_fh (*STDIN ) unless @ARGV ;
76
77
exit $rc ;
77
78
78
- sub tail_fh {
79
+ sub head_fh {
79
80
my $fh = shift ;
80
81
81
82
foreach (1 .. $count ) {
@@ -85,6 +86,26 @@ sub tail_fh {
85
86
}
86
87
}
87
88
89
+ sub new_argv {
90
+ my @new ;
91
+ my $end = 0;
92
+
93
+ foreach my $arg (@ARGV ) {
94
+ if ($arg eq ' --' || $arg !~ m /\A\- / ) {
95
+ push @new , $arg ;
96
+ $end = 1;
97
+ next ;
98
+ }
99
+
100
+ if (!$end && $arg =~ m /\A\- ([0-9]+)\Z / ) { # historic
101
+ push @new , " -n$1 " ;
102
+ } else {
103
+ push @new , $arg ;
104
+ }
105
+ }
106
+ return @new ;
107
+ }
108
+
88
109
__END__
89
110
90
111
=pod
You can’t perform that action at this time.
0 commit comments