I am wondering whether it is a Don't care symbol (X) in Perl.
I have a 50-bit binary input (actually, I used BigInt). If the input is matched with data in database, I would return a pre-defined value.
Let's say the data in the database is 11001100100010110111110110101001000010110101111101 .
If the input is X1001100100010110111110110101001000010110101111101, I would like to treat that it is a matched case because X can be 1 or 0. I know a way to split 50 bits in 50 1-bit and make an exception, but I would prefer to handle 50-bit together.
test.pl (main code, looks messy but the operation is simple, read database and input file and return an output file including a pre-defined value for the matched case. run by test.pl ) :
#!/usr/bin/perl
use strict;
#use warnings;
use Math::BigInt;
#use Math::Gauss ':all';
#use Math::Gauss;
use 5.010;
use List::Util qw(sum);
my $Astrip="cmp_top.iop.sparc0.exu.rml.";
my $Aj=0;
my @Aoutput;
my $At=0;
my $Agen;
my @Aitems; my @Aweights;
my @Aitems_p; my @Aweights_p;
my $Ap=0;
my $Aselected_p = 0;
my $Atotal_p; my $Arand_p; my $Alimit_p;
my $Ai=0; my $Am=0; my $Ak=0;
my $Atotal; my $Arand; my $Alimit;
my $Aselected =0; my $Attemp=0; my $Ane=0; my $Asum=0;
my $Al=0; my $Attest=0;
#### change edb workload - matmul
open(CSV,'database.db')||die("Cannot open edb file $!");
my @Aedb;
while(<CSV>){
my @Arow=split(/\t/,$_);
push(@Aedb,\@Arow);
}
close CSV || die $!;
# if ($At == 0) { goto ASTART; }
my @Ainput=do{
open my $Afh,"<","test.input" or die("Cannot open an input file $!");
<$Afh>;
};
for (my $An=0; $An < (scalar @Ainput); $An +=3) {
### First loop
$Attest = 0;
for ($Ai=0; $Ai < (scalar @Aedb); $Ai +=2) {
$a = Math::BigInt->new("$Aedb[$Ai][1]");
$b = Math::BigInt->new("$Ainput[$An]");
if ( $a == $b ) {
$a = Math::BigInt->new("$Aedb[$Ai+1][1]");
$b = Math::BigInt->new("$Ainput[$An+1]");
if ( $a == $b ) { $Attemp=0;
$Attest++;
$Agen=$Ainput[$An+2];
if (not defined $Agen) { $Arand_p = rand();}
else { $Arand_p = $Agen; }
#$Attemp=0;
for ($Aj=2; $Aj < scalar @{ $Aedb[$Ai+1] }; $Aj++) {
if ( $Aedb[$Ai+1][$Aj]/$Aedb[$Ai+1][2] > $Arand_p ) {
$At++;
$Aedb[$Ai][$Aj] =~ s/\n//g;
$Aoutput[$At+$An/3]= $Astrip.$Aedb[$Ai][$Aj];
$Attemp++;
}
}
#$Aoutput[$An/3+$At-$Attemp]= $Attemp;
}
}
}
}
open(my $Afh2, '>', 'test.output');
print $Afh2 join("\n", @Aoutput);
close $Afh2;
database.db (database file):
0.1 11001100100010110111110110101001000010110101111101 rml_irf_old_e_cwp_e[1] rml_irf_new_e_cwp_e[1] rml_irf_swap_even_e rml_irf_old_e_cwp_e[0] rml_irf_new_e_cwp_e[0] rml_irf_swap_odd_e
0.1 11101100110010011011001101100111001001100000010011 3.923510310023e-06 3.19470818154393e-08 7.05437377900141e-10 7.05437377900141e-10 4.89200539851702e-17 5.01433479478681e-19
0.1 10000110001111010010111101110011001001011110000100 rml_irf_new_e_cwp_e[1] rml_irf_new_e_cwp_e[0]
0.1 01110111010010000000101001000001100011011100011111 0.052908822741908 2.7185508579738e-05
0.1 01001100100100001011101000011111100101111011000111 rml_irf_new_e_cwp_e[1]
0.1 00111101000100001101010111010100000111100100100101 1.09213787524617e-25
0.1 00001000011110000101010110111000000111011110011001 rml_irf_new_e_cwp_e[1] rml_irf_new_lo_cwp_e[1] rml_irf_new_lo_cwp_e[2]
0.1 01101001011110101011111011011011101100110100000101 2.28019753307221e-06 2.89026436307201e-14 2.89026436307201e-14
test.input :
11001100100010110111110110101001000010110101111101
11101100110010011011001101100111001001100000010011
test.output (a pre-defined value for the input and nothing for the unmatched case. I would like to have the same output with X10011...) :
cmp_top.iop.sparc0.exu.rml.rml_irf_old_e_cwp_e[1]
Any help is appreciated.
BigIntfor 50 bits; 2) You could just replaceXwith.and check a pattern match. – Sinan Ünür Jan 13 at 22:20BigInt. I did not go into all the ways one can do this without usingBigInt. – Sinan Ünür Jan 14 at 11:54