Hello Monks,

I have written a script to match a few columns from two text files. Both the files have records in sorted order; so I just have to read lines from both of them and compare the required column values. However some of the columns are numeric while others are strings. The numeric fields might have leading zeroes so I cannot use string comparison for them.
So I have reached a point where I would have to identify the type of value stored in the variables ( which I think I would do by using regex [0-9]+(\.[0-9]+)? ) holding the column values and then compare accordingly. But I think there might be a way to do this context based comparison without getting into all the trouble.
I have tried using numerical comparison (using != operator) in all cases but it doesn't work for string values. e.g.
$var1 = ""; $var2 = "N"; if ( $var1 != $var2) { print "Not Match"; }

does not print "Not Match". Could you please enlighten me in this regard?

Thanks,
Ranjan

In reply to Comparison based on type of value held by variables by ranjan_jajodia

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.