Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

A console output question

by arunhorne (Pilgrim)
on Jun 18, 2002 at 10:41 UTC ( #175331=perlquestion: print w/replies, xml ) Need Help??
arunhorne has asked for the wisdom of the Perl Monks concerning the following question:

Monks

I have written a perl script that reads a very large file line by line and processes it. I want to give the user some feedback, i.e. the current line. So I want to write to the console something like:

Current line is: 31721

I could do it with a print statement, but this produces a new line for each update. Is it possible to overwrite the previous line, i.e. 31721 becomes 31722 and gives the illusion of a counter and looks much neater?

Thanks,

____________
Arun

Replies are listed 'Best First'.
Re: A console output question
by Chmrr (Vicar) on Jun 18, 2002 at 10:47 UTC

    Use print "Current line is: $line\r" or some varient thereof. \r moves the 'cursor' to the start of the line, without moving down a line. You will need to turn buffering off ($|++) for this to work.

    perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'

Re: A console output question
by greenFox (Vicar) on Jun 18, 2002 at 10:51 UTC
Re: A console output question
by demerphq (Chancellor) on Jun 18, 2002 at 11:30 UTC
    I like to use the following:
    use Tie::Cycle; tie my $spinner, 'Tie::Cycle', ["\r-","\r\\","\r|","\r//"]; my $spin_every=10; while (<>) { print $spinner unless $. % $spin_every; # yada-yada-yada }
    The result is a spinning line. Excellent for indicating the program is still alive. The use of mod prevents the output fom happening so often that printing slows the script down noticibly.

    Yves / DeMerphq
    ---
    Writing a good benchmark isnt as easy as it might look.

Re: A console output question
by strat (Canon) on Jun 18, 2002 at 11:18 UTC
    Btw: with a while(<...>) - loop, you can find out about the current line by reading the content of the special Variable $. as long as the Filehandle is still opened. But if you change the variable $/ , $. will give you the number of read blocks (what a block is, is said in $/ ).

    Best regards,
    perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://175331]
Approved by rob_au
help
Chatterbox?
[Corion]: choroba: I'm still using spod5 as my pod-to-ooxml- converter didn't really get off the ground so far
[choroba]: Slidy is basically HTML, so I'm not sure I really fly high :)
choroba should make his presentation scaffolding public
[Corion]: choroba: spod5 converts pod to S5 HTML, so it's also still basic. I find the lack of animations (in the sense of "highlight this", "highlight that" in code) somewhat tedious as I do it with rendered PNGs
[Corion]: I haven't found a good way to include/use the source SVGs I use for creating the PNGs directly as animations
[ambrus]: Presentations come in many different shapes, and so slides do as well.
[Corion]: Doing that in Powerpoint or Ooxml would be nice(r) but I'm much quicker doing the outline of a presentation and the code as Pod
[Corion]: Hurrr - on a machine that is behaving weirdly, I have two processes CROND running. I guess that is the source of unattended jobs sometimes not finding their files anymore...
[ambrus]: Most of the time if I make slides, they're just a formatted document with a medium level of formality (between a well written article and an informal draft), with usually the page breaks chosen carefully and possibly some content repeated between pages.

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2017-09-26 10:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (293 votes). Check out past polls.

    Notices?