Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Trying to take user input as username, read etc/passwd and output user ID

by Fletch (Bishop)
on May 11, 2022 at 03:54 UTC ( [id://11143766]=note: print w/replies, xml ) Need Help??


in reply to Trying to take user input as username, read etc/passwd and output user ID

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.
The cake is a lie.
The cake is a lie.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-19 00:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found