[albany-pm] Typeglobs help!

Patrick Cronin oshihuna at gmail.com
Thu Mar 27 20:26:43 PDT 2014


I have the book Mastering Perl, and a few months ago I thought I was pretty good. Now I just learned that Mastering Perl is only half of what Perl is all about.

Thanks for the info and the link!


> On Mar 27, 2014, at 10:26 PM, Benjamin Holzman <bholzman at gmail.com> wrote:
> 
> 
> Don't think there is a pure perl way to do a dualvar. It's got nothing to do with typeglobs, dualvars work by abusing the IVX slot of a PVIV scalar. See http://cpansearch.perl.org/src/RURBAN/illguts-0.36/index.html#svpviv
> 
> 
>> On Thu, Mar 27, 2014 at 9:46 PM, Patrick Cronin <oshihuna at gmail.com> wrote:
>> I manage a CentOS 5.10 server running perl 5.8.8. For <REASONS>, I can't upgrade it.
>> 
>> For some reason, I can't install the XS version of Scalar::Util, and so I'm stuck using the PP version. Net::OpenSSH relies on Scalar::Util's dualvar function (which is only available in the XS version of Scalar::Util) to create a single scalar holding both an integer and string value. When the scalar is used in a numeric context, the integer value comes out, and when the scalar is used in a string context, the string value comes out. I'm trying to write a quick and dirty PP version of dualvar so I can move on with my life.
>> 
>> I seem to remember seeing this being done, but no amount of googling is getting me there. I've looked up typeglobs and the *foo{THING} construct, but while THING can be SCALAR, it can't be NUMBER or STRING. Does anyone know the magic to make this happen?
>> 
>> I'm trying variations of the following:
>> 
>> my $int = 2;
>> my $string = "test";
>> 
>> my $typeglob = $int;
>> *typeglob{SCALAR} = ${ *string };
>> 
>> print ($typeglob + 2) . "\n";
>> print $typeglob . " YES!\n";
>> 
>> It just feels gross, and it's not working.
>> 
>> Does anyone have the magic?
>> 
>> 	Patrick Cronin 
>> Computer Lover
>> Mobile: +1 518 336 5133
>> Email: oshihuna at gmail.com
>> Skype: patrickcronin12061 
>> 
>> P Please consider the environment before printing this e-mail / attachments 	 
>> 
>> 
>> _______________________________________________
>> Albany-pm mailing list
>> Albany-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/albany-pm
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/albany-pm/attachments/20140327/b80db29f/attachment.html>


More information about the Albany-pm mailing list