Re: counter program by using closure
John W. Krahn wrote: Richard wrote: John W. Krahn wrote: You want something more like this: sub counter { my $count; my $clear = `clear`; my $counting = 'EOF'; %s | Counting...| | %2d | | | EOF return sub { local $| = 1; printf $counting, $clear, ++$count } } my $yeah = counter(); for ( 1 .. 35 ) { sleep 1; $yeah-(); } this is interesting and this also works well. My question is, how does perl know in this instance that %2d is refering to $count.. is it because $clear contains none numeric value or because $count contains numeric value? $counting contains the format string for printf() and the first argument $clear is substituted for '%s' in $counting and the second argument ++$count is substituted for '%2d' in $counting. They are substituted in the same order as they appear. John Just curious, in programming in general, is it possible to do other things while counting is going on? Is this possible in perl? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: counter program by using closure
You might want to look into fork http://perldoc.perl.org/functions/fork.html http://www.tutorialspoint.com/perl/perl_fork.htm On Mon, Dec 15, 2008 at 3:40 PM, Richard rich.j...@gmail.com wrote: John W. Krahn wrote: Richard wrote: John W. Krahn wrote: You want something more like this: sub counter { my $count; my $clear = `clear`; my $counting = 'EOF'; %s | Counting...| | %2d | | | EOF return sub { local $| = 1; printf $counting, $clear, ++$count } } my $yeah = counter(); for ( 1 .. 35 ) { sleep 1; $yeah-(); } this is interesting and this also works well. My question is, how does perl know in this instance that %2d is refering to $count.. is it because $clear contains none numeric value or because $count contains numeric value? $counting contains the format string for printf() and the first argument $clear is substituted for '%s' in $counting and the second argument ++$count is substituted for '%2d' in $counting. They are substituted in the same order as they appear. John Just curious, in programming in general, is it possible to do other things while counting is going on? Is this possible in perl? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- David Schmidt | http://www.fm5.at -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: counter program by using closure
David Schmidt wrote: You might want to look into fork http://perldoc.perl.org/functions/fork.html http://www.tutorialspoint.com/perl/perl_fork.htm thank you.. I was experimenting w/ forks but I definitely need to understand forking better. thanks!! -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: counter program by using closure
John W. Krahn wrote: Richard wrote: wanted to draw a box that's counting up for certain time. Thought I could use the counter but it just displays the box not the number.. can anyone point it out for me? thank you. use warnings; use strict; sub counter { my $count; my $counting = EOF; | Counting... | | ++$count; | | | EOF return sub { print $counting } } my $real_count; my $yeah = counter(); while ($real_count '35') { ++$real_count; system('clear'); $yeah-(); } You want something more like this: sub counter { my $count; my $clear = `clear`; my $counting = 'EOF'; %s | Counting...| | %2d | | | EOF return sub { local $| = 1; printf $counting, $clear, ++$count } } my $yeah = counter(); for ( 1 .. 35 ) { sleep 1; $yeah-(); } John this is interesting and this also works well. My question is, how does perl know in this instance that %2d is refering to $count.. is it because $clear contains none numeric value or because $count contains numeric value? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: counter program by using closure
Richard wrote: John W. Krahn wrote: You want something more like this: sub counter { my $count; my $clear = `clear`; my $counting = 'EOF'; %s | Counting...| | %2d | | | EOF return sub { local $| = 1; printf $counting, $clear, ++$count } } my $yeah = counter(); for ( 1 .. 35 ) { sleep 1; $yeah-(); } this is interesting and this also works well. My question is, how does perl know in this instance that %2d is refering to $count.. is it because $clear contains none numeric value or because $count contains numeric value? $counting contains the format string for printf() and the first argument $clear is substituted for '%s' in $counting and the second argument ++$count is substituted for '%2d' in $counting. They are substituted in the same order as they appear. John -- Those people who think they know everything are a great annoyance to those of us who do.-- Isaac Asimov -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: counter program by using closure
John W. Krahn wrote: Richard wrote: John W. Krahn wrote: You want something more like this: sub counter { my $count; my $clear = `clear`; my $counting = 'EOF'; %s | Counting...| | %2d | | | EOF return sub { local $| = 1; printf $counting, $clear, ++$count } } my $yeah = counter(); for ( 1 .. 35 ) { sleep 1; $yeah-(); } this is interesting and this also works well. My question is, how does perl know in this instance that %2d is refering to $count.. is it because $clear contains none numeric value or because $count contains numeric value? $counting contains the format string for printf() and the first argument $clear is substituted for '%s' in $counting and the second argument ++$count is substituted for '%2d' in $counting. They are substituted in the same order as they appear. John ah.. did not see the %s... and now that makes perfect sense.. thank you very much!!! -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
counter program by using closure
wanted to draw a box that's counting up for certain time. Thought I could use the counter but it just displays the box not the number.. can anyone point it out for me? thank you. use warnings; use strict; sub counter { my $count; my $counting = EOF; | Counting... | | ++$count; | | | EOF return sub { print $counting } } my $real_count; my $yeah = counter(); while ($real_count '35') { ++$real_count; system('clear'); $yeah-(); } -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: counter program by using closure
Richard wrote: wanted to draw a box that's counting up for certain time. Thought I could use the counter but it just displays the box not the number.. can anyone point it out for me? thank you. use warnings; use strict; sub counter { my $count; my $counting = EOF; | Counting... | | ++$count; | | | EOF return sub { print $counting } } my $real_count; my $yeah = counter(); while ($real_count '35') { ++$real_count; system('clear'); $yeah-(); } I am assuming this will not work because above clousure will have no access to variable $count.. trying to see if there is another way to get this done. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: counter program by using closure
On Sat, Dec 13, 2008 at 21:13, Richard rich.j...@gmail.com wrote: wanted to draw a box that's counting up for certain time. Thought I could use the counter but it just displays the box not the number.. can anyone point it out for me? thank you. use warnings; use strict; sub counter { my $count; my $counting = EOF; | Counting... | | ++$count; | | | EOF return sub { print $counting } } my $real_count; my $yeah = counter(); while ($real_count '35') { ++$real_count; system('clear'); $yeah-(); } The problem is that my $counting = EOF; | Counting... | | ++$count; | | | EOF only gets executed once. Move it into your closure to execute it each time the closure is called: #!/usr/bin/perl use warnings; use strict; sub counter { my $count; return sub { my $l = (length ++$count)/2 - .5; my $r = (length $count)/2; print = x 52, \n, |, x 20, Counting..., x 19, |\n, |, x (25 - $l), $count, x (25 - $r), |\n, |, x 50, |\n, = x 52, \n; } } my $yeah = counter(); for (1 .. 35) { system('clear'); $yeah-(); select undef, undef, undef, .25; } -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: counter program by using closure
Chas. Owens wrote: On Sat, Dec 13, 2008 at 21:13, Richard rich.j...@gmail.com wrote: wanted to draw a box that's counting up for certain time. Thought I could use the counter but it just displays the box not the number.. can anyone point it out for me? thank you. use warnings; use strict; sub counter { my $count; my $counting = EOF; | Counting... | | ++$count; | | | EOF return sub { print $counting } } my $real_count; my $yeah = counter(); while ($real_count '35') { ++$real_count; system('clear'); $yeah-(); } The problem is that my $counting = EOF; | Counting... | | ++$count; | | | EOF only gets executed once. Move it into your closure to execute it each time the closure is called:O #!/usr/bin/perl use warnings; use strict; sub counter { my $count; return sub { my $l = (length ++$count)/2 - .5; my $r = (length $count)/2; print = x 52, \n, |, x 20, Counting..., x 19, |\n, |, x (25 - $l), $count, x (25 - $r), |\n, |, x 50, |\n, = x 52, \n; } } my $yeah = counter(); for (1 .. 35) { system('clear'); $yeah-(); select undef, undef, undef, .25; } WOW.. thank you and I will study this code now... this is great!! -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: counter program by using closure
Richard wrote: wanted to draw a box that's counting up for certain time. Thought I could use the counter but it just displays the box not the number.. can anyone point it out for me? thank you. use warnings; use strict; sub counter { my $count; my $counting = EOF; | Counting... | | ++$count; | | | EOF return sub { print $counting } } my $real_count; my $yeah = counter(); while ($real_count '35') { ++$real_count; system('clear'); $yeah-(); } You want something more like this: sub counter { my $count; my $clear = `clear`; my $counting = 'EOF'; %s | Counting...| | %2d | | | EOF return sub { local $| = 1; printf $counting, $clear, ++$count } } my $yeah = counter(); for ( 1 .. 35 ) { sleep 1; $yeah-(); } John -- Those people who think they know everything are a great annoyance to those of us who do.-- Isaac Asimov -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/