Iterating over a string in Perl -
i want make script type string letters 1 one
my $str = 'test string'; @spl = split '',$str; (@spl){ print "$_"; sleep(1); } print "\n";
sleep()
doesn't it's job! makes me wait more 1 second , im getting full text without delay.
in loop, outputting 2 items. there fact output may buffered , therefore buffer may flushed , printed when \n
gets sent.
try setting $|
non-zero value may disable line buffering.
e.g
$| = 1; $|++; // alternative seen
alternatively, same thing:
stdout->autoflush(1); # needs "use io::handle;" on older versions of perl
although not issue here,sleep()
not way of waiting second, on older systems. manual states, there reasons why sleep may take less or more 1 second.
Comments
Post a Comment