
Signature
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
> A Perl scalar value (including array and hash elements) can have more than one
> type simultaneously. Why do you think you need to know what type of value is
> being held?
>
> Rob
hello,
can you show an example of "more than one type simultaneously" ?
this is interesting...
Thanks.

Signature
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
John W. Krahn - 05 Jul 2008 19:22 GMT
>> A Perl scalar value (including array and hash elements) can have more than one
>> type simultaneously. Why do you think you need to know what type of value is
[quoted text clipped - 3 lines]
>
> this is interesting...
I assume that Rob is talking about the $! variable:
$ perl -le' $! = $_ and print "number:", $! + 0, " string:", $! . ""
for 5 .. 9 '
number:5 string:Input/output error
number:6 string:No such device or address
number:7 string:Argument list too long
number:8 string:Exec format error
number:9 string:Bad file descriptor
John

Signature
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Rob Dixon - 05 Jul 2008 23:31 GMT
>> A Perl scalar value (including array and hash elements) can have more than one
>> type simultaneously. Why do you think you need to know what type of value is
[quoted text clipped - 7 lines]
>
> this is interesting...
Perl will convert a scalar value between integer, floating point and string
representations internally depending on what your program does with the value,
and more than one representation can be valid at the same time, for instance if
I write
my $val = '0099';
print $val+1;
then $val will have both a string value of '0099' and an integer value of 99.
The Scalar::Util module has a function dualvar() that lets you assign both the
string and numeric value of a scalar simultaneously. Try the program below.
HTH,
Rob
use strict;
use warnings;
use Scalar::Util qw/dualvar/;
use Devel::Peek;
my $twovals = dualvar 42, 'string';
print $twovals, "\n";
print $twovals+0, "\n";

Signature
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/