Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^4: Perl tk - How to integrate external scripts

by Eliya (Vicar)
on Jan 27, 2012 at 17:46 UTC ( [id://950426]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Perl tk - How to integrate external scripts
in thread Perl tk - How to integrate external scripts

 $mw-> Button (-text =>'Get Statistics', -command =>\&get_statistics($current_file));

The \&get_statistics($current_file) wouldn't work, as it would call the function right away (with an empty $current_file) at the time the button is set up, and set a reference to its return value as the button callback...  In other words, \&func is quite different from \&func(), with the former being a coderef to the function.

What you more likely want is

$mw-> Button (-text =>'Get Statistics', -command => sub { get_statisti +cs($current_file) } );

which would call the function with the current value of $current_file at the time the button is pressed.

Though, as the variable is global anyway, there's no real need to pass it, so you could also leave it at

-command => \&get_statistics

and access $current_file directly in the routine.

The OP's problem is primarily having made $open (i.e. the name of the selected file) scoped locally to the sub open_file, so it's not available outside of the routine.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-23 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found