Skip to content

Commit 35b5dde

Browse files
authored
Reduce the number of globals
* Global variables Attributes-hash, Attributes-scalar and Dirs-list names were aliased within subs; found by perlcritic * Move declarations of some globals into the logical main-block; these don't have to be global * Globals Arg-scalar, Attributes-scalar and DirEntries-list are unused so they disappear * Regression test: cd ~/PerlPowerTools/bin && perl ls -1R .. | md5sum
1 parent 04d90b4 commit 35b5dde

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

bin/ls

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,8 @@ sub format_mode {
108108
}
109109

110110
# ------ define variables
111-
my $Arg = ""; # file/directory name argument from @ARGV
112-
my $ArgCount = 0; # file/directory argument count
113-
my $Attributes = ""; # File::stat from STDOUT (isatty() kludge)
114-
my %Attributes = (); # File::stat directory entry attributes
115-
my %DirEntries = (); # hash of dir entries and stat attributes
116111
my $Getgrgid = ""; # getgrgid() for this platform
117112
my $Getpwuid = ""; # getpwuid() for this platform
118-
my @Dirs = (); # directories in ARGV
119-
my @Files = (); # non-directories in ARGV
120-
my $First = 1; # first directory entry on command line
121113
my $Maxlen = 1; # longest string we've seen
122114
my $Now = time; # time we were invoked
123115
my %Options = (); # option/flag arguments
@@ -509,7 +501,12 @@ if ($#ARGV < 0) {
509501

510502
# ------ named files/directories if arguments
511503
} else {
512-
$ArgCount = -1;
504+
my $ArgCount = -1; # file/directory argument count
505+
my %Attributes; # File::stat directory entry attributes
506+
my @Dirs; # directories in ARGV
507+
my @Files; # non-directories in ARGV
508+
my $First = 1; # first directory entry on command line
509+
513510
for my $Arg (@ARGV) {
514511
if (!exists($Options{'d'}) && -d $Arg) {
515512
$ArgCount++;

0 commit comments

Comments
 (0)