Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I found this post on-line and I am not clear exactly what is going on.
“…you will get a string of bytes with values zero and one, rather then the characters '0' and '1'. To make this printable just 'or' in a string of zeroes of the right length.”
$dd |= '0' x length $dd
I know what the result of this statement is but I am not sure exactly what (how) it is doing (it). I am comparing 2 strings (^) and when I do
$cmp |= '0' x length($cmp); # See rest of code below.
numbers magically appear and I can then see (print) what is in $cmp. So, what exactly does ‘or’ in a string of zeroes mean? Zeroes appear but so do other digits (“A” ^ “C” → 2). What does |= do? (or |= ‘0’) Is there some substitution occurring?
My code:$Str1 = "AAAACCCCGGGGTTTT"; $Str2 = "ACGTACGTACGTACGT"; $cmp = $Str1^$Str2; $cmp |= '0' x length($cmp); print "$Str1\n"; print "$Str2\n"; print "$cmp\n";
**OUTPUT**
AAAACCCCGGGGTTTT
ACGTACGTACGTACGT
0265204764035730
grazie,
romano
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: bitwise string operator
by kennethk (Abbot) on Jun 13, 2013 at 17:23 UTC | |
by romano (Initiate) on Jun 13, 2013 at 19:49 UTC |