Perl variable type assessment

Hello experts,
How we can find out,that what is type of a scalar variable? i.e a scalar var contain a number or a string.
Thanks in advance.

As far as I know Perl uses dynamic typing, meaning the scalar always contains what Perl thinks is expected, eg a Regex will see a string, whereas int() or '*' will see a number if possible.

Zaxon,

Its upto perl interpretor to decide whether variable type is floating ,integer or string.

For instance :
$i =5 ; (For perl interpreter it is a integer datatype)
$i =5.2 ; (For perl interpreter it is a floating datatype)
$i ="MY Perl" ; (For perl interpreter it is a String datatype)

So basically it is all about declaration and assigning value to scalar value will help you to understand the type of data type it is.

Cheers,
gehlnar

pludi and gehlnar thanks, you now, I have a scalar that its value might be integer or a character, and I need to compare it with an if statement, I should be used != or ne ???
Regards

Zaxon,
Use != in case of numeric value comparision and use ne for string/character value comparision.

Cheers,
gehlnar

yes, I know, but might from these two operand the first be an integer and the second be a character! may be.
Help me please. I wanna assessment the type of a scalar variable.

You can "enforce" a certain type by interacting with the desired type, eg. to force a string append and empty string ($var+="") or for a number multiply with 1 ($var*=1)
Note though that this is not always guaranteed to work

Your best option might be to first check if the scalar variable appears to be a number send it to a subroutine that checks it in numeric context, otherwise send it to a subroutine that checks it in string context. See the perl FAQs:

perlfaq4 - perldoc.perl.org

As it also suggests, you can use Scalar::Util or Data::Types to determine what a scalar type is.

Kevin and pludi Thanks a lot.