Hello
charlesx1552 and welcome to the monastery and to the wonderful world of perl!
Without entering in the matter of checking linux users (you got already authoritative suggestions) I'd like to point you to some general perl modern practices:
- I dont see strict nor warnings in use.. this must be a mantra in all your programs
- open(FILE, $filename) or die.. is correct but we dont use bareword filehandles since years: open(my $file_handle, $filename) or die .. is the idiomatic (idiomatic perl => good thing) form (see Is there a problem with using barewords as filehandles ?).
- update you use the implicit opening mode! Please join us in the use of 4 arguments open like in open(my $fh, "<", "input.txt") Explicit -> more readable -> better
- as already said you chomp $username in the wrong place: the right place is just after my $username = <STDIN>; (I added my to your line ;)
- you (at least as presente here) use a poor indentation: you close 3 braces at the same level of indentation while they are not at the same level. See Perl::Tidy for a code beautifier, then it will be by heart
- if A eq B .. if A ne B is logically wrong. if .... else... is what you want. Or in more complex cases if .. elsif .. else
- while dealing with user inputs a typical error is to overlook what you got: I find useful, presenting something to the screen, to enclose these kind of things inside square brackets, like: print "User: [$username] does not exist.\n"; These brackets does not interefere with your output even in case of other brackets, like in: print "Home directory: [$fields[5]]\n";
- as already said @array[0] is an array slice, so it is an array and $array[0] is the first element of the array, so a scalar.
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.