union of 1 and 0 strings
am 24.11.2007 12:40:24 von avilella
Hi,
Question:
I have two strings:
DB<32> x $seqchoice
0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 0 0 '
DB<33> x $outgroup
0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 '
and I want to make the "union" of the "ones" in $outgroup to
$seqchoice, so that I end up with:
DB<32> x $seqchoice
0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 0 '
DB<33> x $outgroup
0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 '
notice the "1" in the penultimate position in $seqchoice.
Any ideas of a regexp that would do for me?
Re: union of 1 and 0 strings
am 24.11.2007 15:13:37 von Michele Dondi
On Sat, 24 Nov 2007 03:40:24 -0800 (PST), "avilella@gmail.com"
wrote:
> DB<32> x $seqchoice
>0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
>1 0 0 '
> DB<33> x $outgroup
>0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
>0 1 0 '
>
>and I want to make the "union" of the "ones" in $outgroup to
>$seqchoice, so that I end up with:
>
> DB<32> x $seqchoice
>0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
>1 1 0 '
> DB<33> x $outgroup
>0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
>0 1 0 '
>
>notice the "1" in the penultimate position in $seqchoice.
Many, many ways to do so. For one thing, spaces are kinda of a PITA.
You may want to get rid of them by splitting into arrays and process
them. Though, I would still go with strings, possibly getting rid of
spaces and using stringwise logical operators and then possibly
massaging back the resulting string:
#/usr/bin/perl
use strict;
use warnings;
my $seqchoice = '000000000000000011111111111111111100';
my $outgroup = '000000000000000000000000000000000010';
local $\="\n";
print for $seqchoice, $outgroup => $seqchoice | $outgroup;
__END__
000000000000000011111111111111111100
000000000000000000000000000000000010
000000000000000011111111111111111110
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
Re: union of 1 and 0 strings
am 25.11.2007 04:36:28 von krahnj
"avilella@gmail.com" wrote:
>
> I have two strings:
>
> DB<32> x $seqchoice
> 0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
> 1 0 0 '
> DB<33> x $outgroup
> 0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> 0 1 0 '
>
> and I want to make the "union" of the "ones" in $outgroup to
> $seqchoice, so that I end up with:
>
> DB<32> x $seqchoice
> 0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
> 1 1 0 '
> DB<33> x $outgroup
> 0 '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> 0 1 0 '
>
> notice the "1" in the penultimate position in $seqchoice.
>
> Any ideas of a regexp that would do for me?
No need for a regexp:
$ perl -le'
$seqchoice = q[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 0 0 ];
$outgroup = q[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 ];
print $seqchoice | $outgroup;
'
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
Is a string the best data structure for your needs?
perldoc -f vec
John
--
use Perl;
program
fulfillment