Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Atomic operations in perl and Tk::IO

by hiseldl (Priest)
on Apr 01, 2003 at 15:03 UTC ( #247248=note: print w/ replies, xml ) Need Help??


in reply to Atomic operations in perl and Tk::IO

Update: <homer_simpson_voice>DOH! cloooosures</homer_simpson_voice>
-- I'll leave the text here so that no else who reads this makes the same mistake. :-)

In your call to component_window(), you assign $pcrh and $pid a la     my ($prch,$pid) = @_;
now, I don't see a shift nor a pop nor any other @_ manipulations, which makes your call to tail_lines() incorrect:

sub component_window { my ($prch,$pid) = @_; ... my $tail = Tk::IO->new( -linecommand => sub { tail_lines($prch, $_[0]) }); ... } sub tail_lines { my ($proc,$text) = @_; ... }
because $_[0] is the same as $prch when you call tail_lines($prch, $_[0]), and this seems to be not what you want.

You should be able to either pass the third element directly or get the third element in a var at the top of your sub (i.e.

sub component_window { my ($prch,$pid,$text)=@_; ...
and pass that...
... my $tail = Tk::IO->new( -linecommand => sub { tail_lines($prch, $text) }); ... }

--
hiseldl
What time is it? It's Camel Time!


Comment on Re: Atomic operations in perl and Tk::IO
Select or Download Code
Re: Re: Atomic operations in perl and Tk::IO
by rinceWind (Monsignor) on Apr 01, 2003 at 15:18 UTC
    because $_[0] is the same as $prch when you call tail_lines($prch, $_[0]), and this seems to be not what you want.
    Sorry, hiseldl, you are not correct. The call to tail_lines is in an anonymous sub, which is a closure, which is passed a line of text by the Tk::IO mechanism.

    See Tk::IO for more details

      I've been writing Tk scripts for over a year now, and I temporarily forgot about closures as callbacks, oops, sorry. I'll leave the post as it is to maintain continuity of the thread and as a reminder to other's using Tk to watch for closures in the callbacks. :-)

      Cheers!

      --
      hiseldl
      What time is it? It's Camel Time!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2015-07-06 03:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (69 votes), past polls