[oak perl] Question: Scalar::Util::dualvar usage in general
Mark Bole
mark at bincomputing.com
Wed Jun 8 17:31:00 PDT 2005
I've made a brief attempt to understand this item, after stumbling
across it while looking up something else -- a typical short story of my
professional life, I guess! ;-)
How is the Scalar::Util::dualvar subroutine implemented? Yes, I've
looked at the C source code in the ext/List/Util/Util.xs file... but as
soon as I saw variables with the string "magic" embedded in the name, I
gave up.
The closest real-life example seems to be Perl built-in errors, in other
words, using errno=2 as an example,
% perl -de 0
Loading DB routines from perl5db.pl version 1.19
Editor support available.
Enter h or `h h' for help, or `man perldebug' for more help.
main::(-e:1): 0
DB<1> $! = 2;
DB<2> print $!;
No such file or directory
DB<3> print $!+0;
2
DB<4> print 'No such file or directory' + 0
0
As a database-oriented person, I'm wondering if there are any other
real-life examples for using this capability -- overloading a variable
with both string and numeric datatypes...
Is there any situation where casting a scalar as "dualvar" would be
preferable to simply creating a hash, with numbers as keys and
corresponding strings as values?
--
Mark Bole
http://www.bincomputing.com
925-287-0366
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/oakland/attachments/20050609/2b5e5041/attachment.html
More information about the Oakland
mailing list