1

I just have begun with Perl and I want to write my own script to scan a document and convert the resulting TIFF file to a PDF file. If the conversion succeeds (using tiff2pdf), I want to print "Done" at the end of the line, but I can't seem to find a hint to do this on the Web.

My guess is that I have to get the geometry of the terminal and count the letters I already printed but that seems to be to complicated. Do you have any advice?

brian d foy
  • 129,424
  • 31
  • 207
  • 592
Florian
  • 512
  • 1
  • 6
  • 12
  • 1
    Are you outputting the PDF source to stdout or to a named file? Have you tried just `print "Done\n";`? Can you explain more what you are trying to do and what you are getting instead? – aschepler Oct 10 '10 at 13:25
  • Do you mean the end of the line or at the side of the terminal window? Those mean different things. – brian d foy Oct 11 '10 at 18:03

1 Answers1

3

You're right about having to inspect the size of the terminal you're printing to. There's many ways to do that, but the most portable and reliable way I'm aware of is Term::Size::Any.

With that, you can get the width of the terminal you're running in:

use Term::Size::Any;
my $cols = chars *STDOUT{IO};

With that, you can then print whatever you want, padded with the right amount of whitespace, e.g.:

printf "% ${cols}s", "Done\n";

Also be aware that programs don't always output to terminals. Output could, for example, be redirected to a file, so you might want to have an appropriate fallback if determining the terminal size fails.

rafl
  • 11,980
  • 2
  • 55
  • 77