Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
No such thing as a small change
 
PerlMonks  

Re: Letter by letter

by Riales (Hermit)
on Apr 20, 2012 at 18:22 UTC ( #966228=note: print w/ replies, xml ) Need Help??


in reply to Letter by letter

Why the sleep after each print? Are you perhaps suffering from buffering?

If not, my initial thought when I think about printing a string letter by letter would be:

$| = 1; print $_ foreach (split '', $string);

Edit: I took a second look at the code you provided. I'm really not sure I understand what you're trying to do now. The second bit of the for loop is supposed to be a test that tells the loop when to stop, but since you're just assigning to $i, I'm pretty sure that loop will run forever.


Comment on Re: Letter by letter
Select or Download Code
Re^2: Letter by letter
by DaveMonk (Acolyte) on Apr 20, 2012 at 18:33 UTC
    Hmm... it prints out the string directly. I want it to instead of print "string", to make it so it has 1 second intervals between each character it's printing... But im going to read the article you linked me.

      Ah, in that case, I think you were mostly on the right track except with the buffering thing and the end case for the for loop.

      $| = 1; foreach my $letter (split '', $string) { print $letter; sleep 1; }

        Somewhat obscure, but I think the following is cute:

        sleep($|=print) for split '', $string;

        print returns 1 if it's successful.

        perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://966228]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2014-04-20 10:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls