Hello, I am trying to take the code below and make it so that if it does not find the user $login instead of just ignoring it, it will put a null or X if you will, if it is not found in that particular /etc/passwd file onto the end of the line. The output should look something like this:

waj4356:server1:server2:X:server4:server5:X:X:server8:server9 zaw8732:X:server2:server3:server4:X:server6:X:server8:X cvf6609:X:X:X:X:server5:server6:server7:X:X
Instead of like this:
waj4356:server1:server2:server4:server5:server8:server9 zaw8732:server2:server3:server4:server6:server8 cvf6609:server5:server6:server7
So that when I split via : delimited I have a standardized type form of 9 servers, X's for the ones the ID is not present in and the server name for the ones in which it is. Instead of using if exists maybe an elseif or other loop type condition would be better, I would appreciate any suggestions. Thanks Again

#!/usr/bin/perl -w use strict; my %USERS; foreach my $file (<passwds.*>) { open(PASSWD,$file); my $strip=$file; #strips passwd. from passwd.server $strip =~ s/passwds\.//; while(<PASSWD>) { my($login,$gcos) = (split(':',$_))[0,4]; if(exists $USERS{$login}) { push(@{$USERS{$login}},$strip); } else { $USERS{$login} = [$strip]; } } close(PASSWD); } open(NEWFILE,">file3") || print "Can't open file3: $!\n"; foreach my $login (sort keys %USERS) { print NEWFILE "$login:".shift(@{$USERS{$login}}).":"; print NEWFILE join(':',@{$USERS{$login}})."\n"; } close(NEWFILE); print "the Active Servers listing is done\n";

In reply to Standardized Template by tux242

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.