perlquestion
rahulgupta70
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.