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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|