Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: filtering an array

by philiprbrenan (Monk)
on Sep 01, 2012 at 19:41 UTC ( #991187=note: print w/ replies, xml ) Need Help??


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)


Comment on Re: filtering an array
Select or Download Code
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.

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991187]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2014-09-22 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (185 votes), past polls