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


in reply to filtering an array

use feature ":5.14"; use warnings FATAL => qw(all); use strict; use Data::Dump qw(dump pp); my @positions; for(split /\n/, <<'END') 1 ACAC 2 AGAC 3 AGTC 4 ACCA END {push @positions, [split/ /] unless /[GT]/; } say "With bases: ", dump(@positions); $_ = $_->[0] for @positions; say "Without bases: ", dump(@positions);

Produces

With bases: ([1, "ACAC"], [4, "ACAC"]) Without bases: (1, 4)

Replies are listed 'Best First'.
Re^2: filtering an array
by philiprbrenan (Monk) on Sep 01, 2012 at 20:15 UTC

    The script will work as long as the string is one or more characters long and does not contain spaces.

Re^2: filtering an array
by prbndr (Acolyte) on Sep 01, 2012 at 19:50 UTC

    i should say that the string is just one single letter, either an "A" "T" "G" or "C", not multiple letters combined.