Say there are two integers of scalar. I want to substract them by digits.
like this: 1,2,3,4,5,6 - 2,9,8,4,7,6 = -1,-7,-5,0,-2,0
When I tried it, I split the two scalars in to 2 arrays of single digits, then performed digit substract. However the results are float numbers.
Appreciate any good suggestions.
Update ###################################
open(FILEIN, "table.txt"); #numbers table which only has 0 and 1. open FILEOUT, ">>data.txt"; #opens data.txt in read-mode my $input="01110011001111100010111101011111000100110000000000000001111 +111101101111101011010"; my @seed = split //; while(<FILEIN>){ #reads line by line from FILE which + is the filehandle for data.txt #chomp; my $temp=''; my @ca = split //; #$_ =~ tr/ /\n/; my $count = 0; foreach my $digit (@ca){ @seed[$count] = @seed[$count] - $_; $count++; } print FILEOUT "@seed\n"; #shows you what we have read } close FILEIN; close FILEOUT;
In reply to Subtraction by digit by zli034
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |