That's really strange. Are you sure that $n1 and $n2 are assigned with literal value as you do, and not from any external resources or inputs?

Update: Following your update, now we know that $n1 is splitted out from $some_string. But, where the heck this $some_string came from? It's the ultimate source of the data you need to tell so we know how is the data originally or initially the first time it arrives to the perl interpreter or your script. Don't emulate by literally assinging it to a variable if that's not actually the case since we'll just get nowhere.

$ cat diff.pl use strict; use warnings; my $n1 = '-933'; # the same result my $n2 = '-1039'; # without quotes my $diff = $n1 - $n2; print "diff: $diff\n"; $ perl diff.pl diff: 106 $ perl -V Summary of my perl5 (revision 5 version 8 subversion 8) configuration: Platform: osname=linux, osvers=2.6.9-22.18.bz155725.elsmp, archname=i386-lin +ux-thread-multi uname='linux hs20-bc1-6.build.redhat.com 2.6.9-22.18.bz155725.elsm +p #1 smp thu nov 17 15:34:08 est 2005 i686 i686 i386 gnulinux '

Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!


In reply to Re: Subtracting Stringified Negative Numbers by naikonta
in thread Subtracting Stringified Negative Numbers by monkfan

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.