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/


Reply via email to