wube has asked for the wisdom of the Perl Monks concerning the following question:

I have created an array with the following code:
#!/usr/local/bin/perl -w local $ENV{"PATH"} = "/usr/openv/netbackup/bin/admincmd" ; open REPORT, "bpclclients class_name -allunique -noheader |" or die "C +an't open bpclclients : $!" ; my @rpts = <REPORT>; print @rpts ; close REPORT;
Snippet of output from the print shows :
Novell NetWare novellqa Solaris Solaris8 nurse-b PC Windows2000 pub01pi Here comes the questions: 1. How do I eliminate all rows with "PC" in col 1 from the array. 2. How do I sort the array by col 1 3. How do I collapse the array into a list ie: delete col 1 and col 2 Thanking everyone in advance.

Replies are listed 'Best First'.
Re: Questions about arrays
by Zaxo (Archbishop) on Oct 16, 2002 at 13:13 UTC

    Assuming that splitting on spaces is good enough,

    1. my @no_pc = grep {not /^PC/} @rpts;
    2. my @sorted = sort @rpts;
    3. my @modified = map {(split ' ',$_, 3)[2]} @rpts;
    4. After Compline,
      Zaxo

Re: Questions about arrays
by derby (Abbot) on Oct 16, 2002 at 13:17 UTC
Re: Questions about arrays
by tadman (Prior) on Oct 16, 2002 at 14:05 UTC
    Like Zaxo but different:
    1. my @no_pc = grep { !/^PC\b/i } @rpts;
    2. my @sorted = sort { uc($a) cmp uc($b) } @rpts;
    3. my @modified = map { /^\S+\s+\S+\s+(.*)/ } @rpts;
    In the first two cases, I'm just not assuming everything comes through squeaky clean, that there could be case changes, or further, some kind of "PCx" type entry. In the third, it's merely that I'm picking off the first two "words" as there might be additional information, and stick to the letter of the request being merely to remove columns 1 and 2.