P is for Practical | |
PerlMonks |
Re: Trying to take user input as username, read etc/passwd and output user IDby Fletch (Bishop) |
on May 11, 2022 at 03:54 UTC ( [id://11143766]=note: print w/replies, xml ) | Need Help?? |
For one thing you split after trying to look at individual elements of your array so that’s the first thing to fix. Also @array[1] is a one element slice and isn’t the right way to access $array[1]. Secondly unless you have a real good reason you probably want to be using getpwnam and friends instead of manually parsing the local passwd file. That will work where (say) accounts are coming from ldap or nis and you’ll get back a list of the fields if the user is valid and don’t need to parse anything yourself. also you chomp the user name scalar each line of your input file but don’t muck with $_ each line which probably isn't what you want either. good grief I’m half asleep and glossed over the exit calls. To start since you don’t split the line first the second if block will always be true and you’ll never read past the first line. Even if you were properly splitting things up earlier each time through the loop if you ever don’t have the first line matching that’s always going to bail out.
The cake is a lie.
In Section
Seekers of Perl Wisdom
|
|