I have perl scalar variable "my $value1" and "my $value2" I read some values from in $value1 and $value2. Now The input can be both a string or integer. I need to compare $value1 and $value2. Now ideally if it is an integer or float then I should be doing IF($value1 == $value2). If it is a string then I should be doing IF($value1 eq $value2). Is there any way to differentiate between a string and integer or float for a perl scalar variable. Also The second IF (if ($value1 eq $value2)) works well for both integer and string. Is there any case where it fails to do that. Thanks for you reply Rahuketu Thanks Everybody for a quick reply. By your views I gather that I should write a strong regular expression to distinguish whether a given scalar is a string or integer(both -ve and +ve). <code>if($value =~ /regexp to match inetegers/){ $isInteger = 1; }else{ $isInteger = 0; }<\code> Thanks I will soon come up with a regexp to have your views.

In reply to Is a integer or string. by rahulgupta70

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.