Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^2: multiple method calls against the same object, revisited

by Aristotle (Chancellor)
on Dec 28, 2004 at 09:32 UTC ( #417732=note: print w/replies, xml ) Need Help??

in reply to Re: multiple method calls against the same object, revisited
in thread multiple method calls against the same object, revisited

There's nothing really wrong with it, but I find it's wordier than it needs to be. Look at what the Perl6 idiom looks like; much quieter visually. Trying to retrofit the construct for this use can lead to some awkward choices: f.ex, I understand why you put the assingment in the for list rather than on the my line before it, but isn't that really the wrong way around? There's no reason to pick one over the other in terms of effective length, but of course putting the assignment on the my line makes the for line stick out like a sore thumb…

If I really wanted to use $_ as “it”, I'd probably use a do block:

my $window = do { local $_ = Gtk2::Window->new( "toplevel" ); $_->signal_connect( delete_event => sub { Gtk2->main_quit } ); $_->set_title( "Test" ); $_->set_border_width( 15 ); $_->add( do { local $_ = Gtk2::Button->new( "Quit" ); $_->signal_connect( clicked => sub { Gtk2->main_quit } ); $_; } ); $_->show_all(); $_; };

That mirrors the structure I achieve with my snippet most closely. But it needs those ugly $_; strewn in there and I'm still mentioning $_ a million times — a blanket of noise covering the code.

Make no mistake, I'm not 100% satisfied with what this snippet allows, either. But until we have Perl6 in our hands, it won't be possible to do much better than it.

Makeshifts last the longest.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://417732]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2021-04-21 18:45 GMT
Find Nodes?
    Voting Booth?

    No recent polls found