I tried to clean up your code and came up with this:
#!/usr/bin/perl -w
use strict; # Always use strict;
open(PASSWD, '/etc/passwd') || die "Could not open /etc/passwd: $!\n";
my %where;
while (<PASSWD>)
{
my @linesplit = split /:/; # No need to use $line,
# @array1 or @array3
@where{$linesplit[0]} = $linesplit[3];
}
close (PASSWD) || die "Error closing file: $!\n"; #Close an opened fil
+e!
foreach my $i (grep {$where{$_} > 1000} keys %where)
{
system ("find '/home/u1' -user $i -print > $i");
}
Some notes:
- You should always use strict. You declared some variables
lexically and others not. Strict would force you into declaring
every variable
- I don't see why you use @array1 and @array3. My version does
the same and does not use them
- Why did you add the \t and the \n
to the line where you build the %where hash?
- It makes no sense to build the where hash, and flush it
immediately after each iteration of the while loop. That is what
you're doing. That's why I declared %where before the while loop
and moved the foreach loop out of that while
- Update: thanks to OeufMayo: always check the return values of open() and close()
HTH
Jouke Visser, Perl 'Adept'
Using Perl to help the disabled: pVoice and pStory