in reply to Re^2: Make array from field of another array
in thread Make array from field of another array

You can access only one element of the split result by using a list index.

my @new_array = map { (split /:/)[3] } @old_array;

Note that I have relied on split's default of splitting $_ when not provided with an explicit string. So the above is exactly equivalent to

my @new_array = map { (split /:/, $_)[3] } @old_array;

Replies are listed 'Best First'.
Re^4: Make array from field of another array
by Saved (Beadle) on Apr 07, 2011 at 17:14 UTC
    That is it exactly, Thanx very much.
Re^4: Make array from field of another array
by Saved (Beadle) on Apr 07, 2011 at 17:17 UTC
    That is it exactly, Thanx very much.
Re^4: Make array from field of another array
by Saved (Beadle) on Apr 07, 2011 at 18:35 UTC
    This appears to work, thanx for your help.
    #!/usr/bin/perl -w #<UnusedGrp.pl> Find unused Groups in /etc/group use strict; my $GROUPfile="/etc/group"; my $gfpid = open(GFILE, "<$GROUPfile") or die "$GROUPfile File Not Fou +nd: $!\n"; my $PASSWD="/etc/passwd"; my $pfpid = open(PFILE, "<$PASSWD") or die "$PASSWD File Not Found: $! +\n"; my @PWLINES = <PFILE>; my @GIDS = map { (split /:/)[3] } @PWLINES; while (my $line = <GFILE>) { my @GRP = split(/:/, $line); if (length($GRP[3]) < 2){ #print "$GRP[0]:$GRP[2] is zero length\n"; if ( ! (grep $_ eq $GRP[2], @GIDS)) { print "$GRP[0]:$GRP[2] is Empty & not referenced in /etc/passwd +\n"; } } }