[albany-pm] Typeglobs help!

Benjamin Holzman bholzman at gmail.com
Thu Mar 27 19:26:23 PDT 2014


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?
>
> ------------------------------
> [image: Patrick's Avatar]*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/1bdecab5/attachment-0001.html>


More information about the Albany-pm mailing list