dash2 has asked for the wisdom of the Perl Monks concerning the following question:

Purely for fun, I did this:

package Array; use Tie::Array; use strict; use vars qw/@ISA $AUTOLOAD/; @ISA = qw/Tie::StdArray/; sub TIEARRAY { my $class = shift; return bless [], $class; } sub AUTOLOAD { my $self = shift; my $method = $AUTOLOAD; $method =~ s/.*:://; foreach (@$self) { no strict 'subs'; $_->$method(@_); } }

So now I can do

my @array; tie (@array, 'Array'); @array = (new Foo,new Bar,new Baz); my $obj = tied @array; $obj->method; # calls method on all objects in the array

But obviously that isn't 31337 enough. So can some obfuscation genius figure out a way to do this:

my @array; tie (@array, 'Array'); @array = (new Foo,new Bar,new Baz); @array->method; # calls method on all objects in the array

?

dave hj~

Replies are listed 'Best First'.
Re: 31337 array dereferencing
by Masem (Monsignor) on Jan 31, 2002 at 15:50 UTC
    See Tie::Array::Iterable, a module I wrote in which the key object variable can not only be treated as an array, but as an object as well. The key is that you'll want to create a special array object via a new method, in which you do the necessary tie'ing to make things work.

    -----------------------------------------------------
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
    "I can see my house from here!"
    It's not what you know, but knowing how to find it if you don't know that's important