zli034 has asked for the wisdom of the Perl Monks concerning the following question:
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Subtraction by digit
by hipowls (Curate) on Feb 11, 2008 at 09:00 UTC | |
|
Re: Subtraction by digit
by ysth (Canon) on Feb 11, 2008 at 08:56 UTC | |
|
Re: Subtraction by digit
by j1n3l0 (Friar) on Feb 11, 2008 at 10:24 UTC | |
by hipowls (Curate) on Feb 11, 2008 at 11:26 UTC | |
|
Re: Subtraction by digit
by moklevat (Priest) on Feb 11, 2008 at 15:18 UTC | |
|
Re: Subtraction by digit
by syphilis (Archbishop) on Feb 11, 2008 at 09:13 UTC | |
|
Re: Subtraction by digit
by eric256 (Parson) on Feb 11, 2008 at 17:11 UTC | |
|
Re: Subtraction by digit
by graff (Chancellor) on Feb 12, 2008 at 07:25 UTC |