in reply to User Existance?
You also indicate that you would like to add users that are not on your system. It is for this reason that I suggest using a hash lookup (which is very fast) in this untested code.
Of course /user/defined/file should be set up like /etc/passwd if you care about the extra fields. Additionally, if you don't want to use /etc/passwd - I have shown the framework - you can have an "ok" %User and a "blacklist" %BadUser.#!/usr/bin/perl -w use strict; my %User; { local @ARGV; @ARGV = qw(/etc/passwd /usr/defined/file); while (<>) { chomp; my @field = split /:/; unless (exists $User{$field[0]}) { $User{$field[0]} = \@field; } else { print "WARNING: Duplicate found for $field[0]\n"; } } } my $testuser = "blah"; if (exists $User{$testuser}) { print "$testuser exists on system\n"; print "Field 4 for $testuser is $User{$testuser}->[3]\n"; }
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: User Existance?
by Anonymous Monk on May 17, 2003 at 17:49 UTC | |
by Limbic~Region (Chancellor) on May 17, 2003 at 18:01 UTC | |
|
Re: Re: User Existance?
by Anonymous Monk on May 17, 2003 at 20:41 UTC | |
by isotope (Deacon) on May 17, 2003 at 23:08 UTC | |
by The Mad Hatter (Priest) on May 18, 2003 at 00:25 UTC |