Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: uid file finder

by Jouke (Curate)
on Jun 07, 2001 at 13:50 UTC ( [id://86503]=note: print w/replies, xml ) Need Help??


in reply to uid file finder

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://86503]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-24 03:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found