Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Widget functions with arguments 2

Status
Not open for further replies.

AMiSM

Technical User
Jan 26, 2006
128
0
0
US
Hi, all!
Is there any way to supply arguments to functions called with widgets?
e.g.
$button = $mw -> Button ( -command => \&do_this( this_way ) )
 
Yep. :)

Code:
my $button = $mw->Button (
   -command => [ \&do_this, 'something', 'to', $send ],
)->pack;

-command takes a list reference starting with the code reference and then a list of arguments to send to it. Also note that certain widgets always receive their own reference as $_[0] (I think Buttons do this, but other widgets don't), so that the first argument you send might be $_[1].

So it's always a good idea to print what @_ is when you're using this on a new type of widget for the first time to find out where everything is.

Code:
-command => [ sub {
   print "\@_ = @_\n";
}, 'arg1', 'arg2' ],

-------------
Cuvou.com | My personal homepage
Project Fearless | My web blog
 
I think I remember now, reading about the list thing.
Thanks again, man!
 
The brackets in...

-command => [ \&do_this, 'something', 'to', $send ],

...are they syntactical; required, or are you just using them as a "something-like-this" literary device?
 
Never mind, I figured it out
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top