From 13eec9675758800ae7c30537bd11846a39ab4590 Mon Sep 17 00:00:00 2001 From: Michael Mikonos <127171689+mknos@users.noreply.github.com> Date: Fri, 3 Jan 2025 11:31:02 +0800 Subject: [PATCH] expand: garbage collect a global * ARGV is a list of files, which could be empty if stdin default is used * Using a direct copy of ARGV provides no benefit * The usage() function was previously converted to not take any params --- bin/expand | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/bin/expand b/bin/expand index dff478e4..5e8b320f 100755 --- a/bin/expand +++ b/bin/expand @@ -37,7 +37,6 @@ my $Program = basename($0); my %line_desc; my $tabstop = 8; my @tabstops; -my @files; while (@ARGV && $ARGV[0] =~ /\A\-(.+)/) { my $val = $1; @@ -46,12 +45,10 @@ while (@ARGV && $ARGV[0] =~ /\A\-(.+)/) { last; } @tabstops = split /,/, $val; - usage(1) if grep /\D/, @tabstops; # only integer arguments are allowed + usage() if grep /\D/, @tabstops; # only integer arguments are allowed shift @ARGV; } -@files = @ARGV; - # $tabstop is used only if multiple tab stops have not been defined if(scalar @tabstops == 0) { $tabstop = 8; @@ -68,7 +65,7 @@ if(scalar @tabstops == 0) { } } -for my $file (@files) { +for my $file (@ARGV) { my $in; unless (open $in, '<', $file) { warn "$Program: couldn't open '$file' for reading: $!\n"; @@ -79,7 +76,7 @@ for my $file (@files) { } close $in; } -unless (@files) { +unless (@ARGV) { while (<>) { expand_line($_); }