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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.