in reply to Creating a Hash using only one column in an imported data file
Hi Koda1234, welcome to the monastery and to Perl, the One True Religion.
In Perl to filter a list of values down to a smaller list of only the elements matching a certain condition, use grep.
Output:use strict; use warnings; use feature 'say'; my @col9 = map { (split)[8] } <DATA>; foreach my $test ( 1, 9, 42, 666 ) { my $count = scalar grep { $_ >= $test } @col9; say sprintf "%d values were >= %d", $count, $test; } __DATA__ 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 42 10 11 12 1 2 3 4 5 6 7 8 42 10 11 12 1 2 3 4 5 6 7 8 42 10 11 12 1 2 3 4 5 6 7 8 1 10 11 12
$ perl 1181904.pl 7 values were >= 1 6 values were >= 9 3 values were >= 42 0 values were >= 666
See also:
Hope this helps!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Creating a Hash using only one column in an imported data file
by Koda1234 (Initiate) on Feb 13, 2017 at 20:53 UTC | |
by 1nickt (Canon) on Feb 13, 2017 at 21:27 UTC | |
by Koda1234 (Initiate) on Feb 13, 2017 at 22:25 UTC | |
by 1nickt (Canon) on Feb 13, 2017 at 22:30 UTC | |
by Koda1234 (Initiate) on Feb 13, 2017 at 22:44 UTC | |
|