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

your Code:
my @new_array = map {split /:/, $_} @old_array;
Is nearly what I was hoping for, but could you do something to get only one field?
my @new_array = map {split /:/, ${_[3]}} @old_array;

Replies are listed 'Best First'.
Re^3: Make array from field of another array
by kennethk (Abbot) on Apr 07, 2011 at 16:47 UTC
    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;

      That is it exactly, Thanx very much.
      That is it exactly, Thanx very much.
      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"; } } }