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

Hey guys, I have an array with strings in the following format: /dev/md/dsk/d503 2056211 875636 1118889 44% /var How can I search through the array and pull lines that have 90% or above in them. Thanks

Replies are listed 'Best First'.
Re: Array question
by tachyon (Chancellor) on Sep 22, 2004 at 23:22 UTC

    Ah, have you heard of loops and regular expressions? One way.....

    for (@ary) { print if m/\s(\d+)%/ and $1 >= 90; } # as a one liner perl -ne 'print if m/\s(\d+)%/ and $1 >= 90' infile > outfile

    If 99.5% is a valid value you need to replace \d+ with [\d\.]+

    cheers

    tachyon

Re: Array question
by davido (Cardinal) on Sep 22, 2004 at 23:22 UTC

    Try this:

    my @high = grep { m/\s(\d+)\%/ and $1 >= 90 } @array;

    Dave

Re: searching array elements
by chromatic (Archbishop) on Sep 22, 2004 at 23:24 UTC

    grep is the right approach:

    my @found = grep { / 9\d+%/ } @your_array;

    Update: Oh, I was sorting ASCIIbetically. Try:

    my @found = grep { / (?:100|9\d)%/ } @your_array;

      100% ?

        Have you never seen a report of 100% disk usage from the unix 'df' command? It happens.
Re: Array question
by dannyp (Novice) on Sep 22, 2004 at 23:38 UTC
    Thanks, I was close I just couldn't figure out how to pull 90 and above.