Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^4: Tk subroutine

by props (Hermit)
on Sep 24, 2007 at 10:42 UTC ( [id://640689]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Tk subroutine
in thread Tk subroutine

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^5: Tk subroutine
by shmem (Chancellor) on Sep 24, 2007 at 16:08 UTC
    i do get the explicit package name error.

    What I meant with my previous post is the following:

    { # this bracket introduces a lexical scope my $count; # $count declared as a lexical outside the sub sub add_button { #add button entries my $addframe = $frm_name4->Frame( -background=>'yellow', -relief=>'groove', -borderwidth=>5) ->pack(-side=>'top', -fill =>'x'); my $addtxtcount = $addframe->Text( -width=>1, -height=>1) ->pack(-side=>'left', -anchor =>'nw'); # my $addtxtexpense = $addframe->Text( -width=>8, -height=>1) ->pack(-side=>'left', -anchor =>'nw', -padx=>5); my $addtxtcost = $addframe->Text( -width=>8, -height=>1) -> pack(-side=>'left', -anchor =>'nw', -padx=>10); chomp(my $expense = $expenseentry->get()); $expenseentry -> delete('0', 'end'); $addtxtexpense->insert('end',$expense); #cost posting chomp(my $cost = $costentry->get()); $costentry-> delete('0','end'); $addtxtcost->insert('end',$cost); #countig posting $count ++; $addtxtcount->insert('end',$count); #calculate balance my @totalbalance = 0; push(@totalbalance,$cost); foreach( @totalbalance) { my $total += $_; ##write new balance $balancetxt->delete('1.0','end'); $balancetxt->insert('end',$total); #open WRITEFILE , ">>$time.txt" or die "write error\n"; #print WRITEFILE ("$count) $expense $cost \n"); #close WRITEFILE; } } }

    That way you have the $count declared outside the subroutine, and it will not be re-initialized inside the sub at every pass.

    Maybe the subroutine is totally wrong!

    That might well be, but it's up to you to find out...

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-03-29 13:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found