http://www.perlmonks.org?node_id=1004790


in reply to Array Filter and Lookahead

Yet another approach (founded, in part, on moritz' point that the rule for dealing with decimals is UNspecified).

Given the OP, if the the spec is that trailing decimal digits should be truncated to integers (let us hope there's no hidden requirement for rounding :) ) then a two-part approach is also viable.

So, less elegantly but, IMO, very obvious in its tactics and using regular expressions similar to those proposed above, a TIMTOWTDI might look like this:

#!/usr/bin/perl use 5.014; #1004756 my @init_array = ("text text text 1 text", "1 text text text 2 text 3 ", "text 1 text text 2 text", "text text text 1 text 2 3.0", "1 2 3 4 5 6 7 8 9 10 11", "text text text text", ); my ($sub_select, $select, @selected); for $_(@init_array) { $_ =~ s/(.+)\.0\z/$1/; # Truncate trailing decimal numbers say "\t \$_: $_"; # debug ($select) = $_ =~ / .+? (?:(\d+)) (?:[\D]*) $ # EOL /x; push @selected, $select; } my $i = 0; for my $captured(@selected) { say "\t\t" . '#test_filtered' . "[$i]: " . '"' . $captured . '"'; $i++; } =head EXECUTION: C:\>perl 1004756.pl $_: text text text 1 text $_: 1 text text text 2 text 3 $_: text 1 text text 2 text $_: text text text 1 text 2 3 $_: 1 2 3 4 5 6 7 8 9 10 11 $_: text text text text #test_filtered[0]: "1" #test_filtered[1]: "3" #test_filtered[2]: "2" #test_filtered[3]: "3" #test_filtered[4]: "11" #test_filtered[5]: "" =cut