Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Dear Monks, I have several scripts that I would like to be able to run on a variety of systems where I don't control the main installation directories. In particular, one of them is a perl 5.8.0 where the List::Util version is "1.07_00" and therefore refaddr is missing.

I tried creating my own override of the whole List::Util package, but the XS part was not portable to all systems.

Instead, to fill in the missing function, I created the following module:

package PatchPackages; use strict; use version; our $VERSION = qv/0.0.1/; sub import { require Scalar::Util; if (! Scalar::Util->can('refaddr')) { # Copied from more recent Scalar::Util code. # Makes up for this function being missing on some # of our 5.8.0 installations. *Scalar::Util::refaddr = sub ($) { my $pkg = ref($_[0]) or return undef; if (Scalar::Util::blessed($_[0])) { bless $_[0], 'Scalar::Util::Fake'; } else { $pkg = undef; } "$_[0]" =~ /0x(\w+)/; my $i = do { local $^W; hex $1 }; bless $_[0], $pkg if defined $pkg; $i; } } } 1;

This seems a little messy, but it works. Does anyone know of a cleaner way to do this?

In reply to Patching a Package (Scalar::Util) by tall_man

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (7)
    As of 2019-05-25 17:06 GMT
    Find Nodes?
      Voting Booth?
      Do you enjoy 3D movies?

      Results (152 votes). Check out past polls.

      • (Sep 10, 2018 at 22:53 UTC) Welcome new users!