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

Hey, I don't like the way any of these look. Any nicer way to rewrite a call to a series of anonymous subroutines nested inside other subroutines?

C:\Temp>perl -e "$ms= sub { sub{print 'msqrx'}}; $ms->()->();"
msqrx
C:\Temp>perl -e "$ms= sub { sub{print 'msqrx'}}; &{$ms->()};"
msqrx
C:\Temp>perl -e "$ms= sub { sub{print 'msqrx'}}; &{&{$ms}};"

Celebrate Intellectual Diversity

Replies are listed 'Best First'.
(tye)Re: Easier ways to write
by tye (Sage) on Jul 04, 2001 at 01:17 UTC

    Also &{&$x} and &$x->(). Or:

    sub d { &{shift(@_)} } d d $x;

            - tye (but my friends call me "Tye")
Re: Easier ways to write
by bikeNomad (Priest) on Jul 04, 2001 at 00:27 UTC
    Stupid OO/overload tricks:

    use strict; package Subref; sub new { my $class = shift; my $ref = shift; bless($ref, $class); } sub myderef { my $self = shift; 1 while ($self = $self->(), UNIVERSAL::isa($self, 'CODE')); } use overload '<>' => \&myderef; package main; my $ms= Subref->new(sub { sub{print 'msqrx'}} ); <$ms>;
Re: Easier ways to write
by dragonchild (Archbishop) on Jul 04, 2001 at 00:29 UTC
    I don't know how much help this is, but you can do $ms->()();
Re: Easier ways to write
by John M. Dlugosz (Monsignor) on Jul 04, 2001 at 00:25 UTC
    Write a helper function, so you can say callInnermost($ms); That makes it much more readable.