<?xml version="1.0" encoding="windows-1252"?>
<node id="991281" title="Re: filtering an array" created="2012-09-02 10:55:14" updated="2012-09-02 10:55:14">
<type id="11">
note</type>
<author id="917684">
vagabonding electron</author>
<data>
<field name="doctext">
I am still a newbie, but / therefore - what is wrong with using hash here (with keys as line numbers and values as bases)?

&lt;c&gt;
#!/usr/bin/perl -l
use strict;
use warnings;

print "If an array element is a line number and a base together as a string:";

my %positions;

for my $line (split /\n/, &lt;&lt;'END') 
1 ACAC
2 AGAC
3 AGTC
4 ACCA
END

{
	next if $line =~ /[GT]/;
	my ($number, $bases ) = split / /, $line;
	$positions{$number} = $bases;	
}

for my $number ( sort keys %positions )
{
	print "$number =&gt; $positions{$number}";
	print "Just print a number $number";
}

print "If there is an array element for a line number and for a base:";

my @array = ( qw (1 ACAC 2 AGAC 3 AGTC 4 ACCA) );
%positions = ();
for (my $i = 0; $i &lt; @array; $i +=2 )
{
	my ($number, $bases ) = @array[$i, $i+1];
	next if $bases =~ /[GT]/;
	$positions{$number} = $bases;
}

for my $number (sort keys %positions)
{
	print "$number =&gt; $positions{$number}";
	print "Just print a number $number";
}
&lt;/c&gt;

It prints:
&lt;c&gt;
If an array element is a line number and a base together as a string:
1 =&gt; ACAC
Just print a number 1
4 =&gt; ACCA
Just print a number 4
If there is an array element for a line number and for a base:
1 =&gt; ACAC
Just print a number 1
4 =&gt; ACCA
Just print a number 4
&lt;/c&gt;</field>
<field name="root_node">
991184</field>
<field name="parent_node">
991184</field>
</data>
</node>
