format/write question

S

Steve K.

I seem to be having a difficult time understanding formats. I've figured
out how to use formline easy enough, but when trying to test format and
write, using an example from perldoc perlform, it hangs, unless I
comment out the line with the call to write. If I uncomment it, the
program hangs and eats more and more CPU. I don't see how this can be
for such a small program?


#!/usr/local/bin/perl

use strict;

our $text = "line 1\nline 2\nline 3";
format STDOUT =
Text: ^*
$text
~~ ^*
$text
 
D

Darren Dunham

Steve K. said:
#!/usr/local/bin/perl
use strict;
our $text = "line 1\nline 2\nline 3";
format STDOUT =
Text: ^*
$text
~~ ^*
$text
.

write (STDOUT);

I don't see in the 5.6.1 documentation that ^* is supported. So it's
either not supposed to work in older versions, or it wasn't much used
and you've found an old bug.

99% of the formats I've seen and used just worked with simple
fixed-width fields.
I'm also wondering why one would want to use them over printf/sprintf,
especially when they seem to be so much trouble to use. It reminds me a
little of Cobol.

Maybe you don't. But formats do understand line counts per page, so if
you're used to 66 line pages, they take a bit of work out. You'd have
to code some extra logic to do that with printf.
 
G

greymaus

fixed-width fields.


Maybe you don't. But formats do understand line counts per page, so if
you're used to 66 line pages, they take a bit of work out. You'd have
to code some extra logic to do that with printf.

format is a nice low-end word formatter, best used, AFAIknow, for
formatting data extracted with perl into a nicely formed and easily
read report. Pump it into TeX and use \verbatim{}. Filter out a data
field you want from the mass of data.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top