I did try undef, but got warnings, so figured it was verboten. I ought to have continued with my experiments.

Here's something fun. Acme::Ref breaks on recent Perls, but it's a one line patch to fix it. (The _deref function needs to take a long argument instead of an int.)

use strict; use warnings; use feature 'say'; { package Local::Class; sub new { my ( $class ) = ( shift ); bless {}, $class; } sub AUTOLOAD { my ( $method ) = ( our $AUTOLOAD =~ /([^:]+)$/ ); if ( $method =~ /^(ARRAY|HASH|SCALAR|REF)/i ) { require Acme::Ref; my $real_coderef = $_[0]->can("HANDLE_$1") or die "Cannot handle $1 method"; splice @_, 1, 0, do { local $SIG{__WARN__} = sub {}; Acme: +:Ref::deref($method); }; goto $real_coderef; } return if $method eq 'DESTROY'; die "Could not load $method via AUTOLOAD"; } sub HANDLE_ARRAY { my ( $self, $array, @args ) = ( shift, shift, @_ ); say for @$array; } sub HANDLE_HASH { say "whatever"; } # etc... }; my $object = 'Local::Class'->new(); my $array = [ "Hello", "world" ]; $object->$array; $object->${\ [ "And", "again" ] };

In reply to Re^9: How can I call a Perl sub with an object from a sub name stored in a var? by tobyink
in thread How can I call a Perl sub with an object from a sub name stored in a var? by misterperl

Title:
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, details, 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, summary, 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.