In Perl, what is the difference between
$status = 500;
and
$status = '500';
Not much. They both assign five hundred to $status
. The internal format used will be different initially (IV vs PV,UTF8=0), but that's of no importance to Perl.
However, there are things that behave different based on the choice of storage format even though they shouldn't. Based on the choice of storage format,
&
, |
and ^
) guess whether their operands are strings or not.open
and other file-related builtins encode the file name using UTF-8 or not. (Bug!)As already @ikegami told not much. But remember than here is MUCH difference between
$ perl -E '$v=0500; say $v'
prints 320
(decimal value of 0500 octal number), and
$ perl -E '$v="0500"; say $v'
what prints
0500
and
$ perl -E '$v=0900; say $v'
what dies with error:
Illegal octal digit '9' at -e line 1, at end of line Execution of -e aborted due to compilation errors.
And
perl -E '$v="0300";say $v+1'
prints
301
but
perl -E '$v="0300";say ++$v'
prints
0301
similar with 0x\d+
, e.g:
$v = 0x900; $v = "0x900";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With