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

This may be a relatively simple question, but I can't seem to find the answer. Anyhow, when I'm writing a shell script and I want an open ended print, I do this...
# printf "Starting process.....\c" .... some code .... # printf "DONE!\n"
...which outputs something like this...
Starting process..... <waits till pricess finishes>DONE!
However, perl doesn't like the '\c' with "print" or "printf". And if I don't put anything at the end of my string, perl waits until the action(s) are completed and then prints the whole line. How can I print the starting statement, THEN print the "DONE!" (or whatever)?
- I know nothing....

Replies are listed 'Best First'.
Re: Shell-like "print"
by belg4mit (Prior) on Oct 14, 2003 at 21:10 UTC
Re: Shell-like "print"
by Abigail-II (Bishop) on Oct 14, 2003 at 21:59 UTC
    Odd. When I use 'printf' in the shell, it prints "\c" as "\c". Nothing special about that. It's *echo* for which \c in (some) implementations is special.

    Anyway, in Perl if you want print or printf to not print a newline, just don't put a newline in the string to print. It will only print out a newline if you tell it to print a newline.

    As for Perl printing out the line until the in between code is finished, that's because of buffering. You can turn buffering off by setting $| to 1.

    See also 'man perlvar'.

    Abigail

      Abagail, I'm not sure what shell you're using, but I'm using Solaris Korn Shell. '\c' doesn't show up in the printf output, but I don't know if there's a difference between leaving it off altgether or not. I read the article in the first reply, and I think I can make it work, or work around it. Thanks! :)
      - I know nothing....
Re: Shell-like "print"
by eoin (Monk) on Oct 14, 2003 at 21:57 UTC
    If I understand your "fadhb" right then you shouldn't have to put "\c" in at all, or use buffering.
    If this is what you mean.
    print "Starting process.......\n"; ...........Some Irrelevent Code......... print "DONE!\n"
    This will produce
    Starting process.......
    DONE!
    
    Hope this helps.

    All the Best, Eoin...

    If everything seems to be going well, you obviously don't know what the hell is going on.



    P.s.You should look up some nodes on how to write questions proberly and this way you will get more responses. ;)
    Try here for some help on posting comments!
      "fadhb"??????
      - I know nothing....
        Fadhb is the Irish word for problem.

        All the Best, Eoin...

        If everything seems to be going well, you obviously don't know what the hell is going on.