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 Chriss Miller 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
Joined
Jan 26, 2006
Messages
128
Location
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