Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

loading. . . . . . done! I want to code a perl script that will print 'loading', a period, then pause for about a second, then another period, then the pause again, then another period I hope you get the idea. I have tried some variations of the following but nothing works the way I want it to. All I get is a long pause and then the script prints out the end result with out showing what I want displayed leading up to the done!
#!/usr/bin/perl -w use strict; my $x = 0; print "Loading. . "; while ( $x < 8 ){ sleep(2); print ". "; $x++; } print "done!\n";

Replies are listed 'Best First'.
Re: loading. . . . . . . . . done!
by clintp (Curate) on Jul 06, 2001 at 17:50 UTC
    Buffering is not your friend here...perldoc perlvar for more info.
    #!/usr/bin/perl -w use strict; my $x = 0; $|=1; # Turn on auto-flushing print "Loading. . "; while ( $x < 8 ){ sleep(2); print ". "; $x++; } print "done!\n";
Re: loading. . . . . . . . . done!
by arturo (Vicar) on Jul 06, 2001 at 17:54 UTC

    Try unbuffering your output:

    use strict; $| =1; #unbuffer output print "Loading . ."; for (1..8) { sleep 2; print " ."; } print "\nDone.\n";

    Read all about $| and other special variables in perldoc perlvar or perlvar. HTH

    perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'