To argue that Perl should provide a function to convert a scalar to a float because it provides a function to convert a scalar to an integer is a valid argument, but the premise is false. Perl doesn't have a function that converts a scalar to an integer.
int implements the mathematical function. It doesn't necessarily return an integer in the C sense of the word. For example, here's an example where int returns a float (NV):
>perl -MDevel::Peek -e"Dump int(2**32);" SV = NV(0x184ac1c) at 0x226be4 REFCNT = 1 FLAGS = (NOK,pNOK) NV = 4294967296
Type conversion is always done implicitely in Perl.
If Perl needs a string, the scalar will be coerced into a string.
If Perl needs a number, the scalar will be coerced into a number.
If Perl needs a boolean, the scalar will be coerced into a boolean.
etc.
Of course, you are free to produce your own conversion routines.
sub to_string { "$_[0]" } sub to_num { 0+$_[0] } sub to_bool { !!$_[0] } etc.
In reply to Re^3: When is 'eval' too inefficient?
by ikegami
in thread When is 'eval' too inefficient?
by argv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |