I'm starting to learn perl, using the Wrox Beginning Perl available on perl.org and have a question regarding a for loop example they provide in Chapter 3.
#!/usr/bin/perl
use warnings;
use strict;
my @count = (1..10);
for (reverse(@count)) {
print "$_...\n";
sleep 1;
}
print "Blast Off!\n"
This is the script they provide, and it works as expected. It displays a number followed by ... every second, waiting a second in between each number. When done, it displays Blast Off!
However if I remove the newline from the print statement, the behaviour changes. The script silently waits 10 seconds and then displays all 10 numbers and Blash Off!
at once. Why the change?
#!/usr/bin/perl
use warnings;
use strict;
my @count = (1..10);
for (reverse(@count)) {
print "$_...";
sleep 1;
}
print "Blast Off!\n"