On Sat, Dec 13, 2008 at 21:13, Richard <[email protected]> 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: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/