in reply to filtering an array
It prints:#!/usr/bin/perl -l use strict; use warnings; print "If an array element is a line number and a base together as a s +tring:"; my %positions; for my $line (split /\n/, <<'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 => $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 < @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 => $positions{$number}"; print "Just print a number $number"; }
If an array element is a line number and a base together as a string: 1 => ACAC Just print a number 1 4 => ACCA Just print a number 4 If there is an array element for a line number and for a base: 1 => ACAC Just print a number 1 4 => ACCA Just print a number 4
|
|---|