format/write question
am 16.08.2007 18:56:41 von savagebeaste
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
.
write (STDOUT);
I tested with 5.6.1 and 5.8.2 (linux) and no go. Same thing on my
Windows system with 5.6.1, but with 5.8.7 it works...
C:\>perl5.8.7 format_test_002.pl
Text: line 1
line 2
line 3
(all others I've tried it just hangs and eats resources.)
What am I mising here? I'm just trying to figure out how formats work in
general, more for educational/historical purposes I guess, and am just
trying to learn form examples, but the examples don't seem to work
except in one case out of four. Are there better examples out there that
work more universally? Or am I (or the example) doing something wrong?
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.
Thanks.
Re: format/write question
am 17.08.2007 00:57:17 von Jim Gibson
In article <5ijdueF3p2qmfU1@mid.individual.net>, Steve K.
wrote:
> I seem to be having a difficult time understanding formats.
[snip]
>
> 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.
In 10 years of Perl programming, I have never used formats. I would
guess that the majority of Perl programmers would say the same. I just
use printf.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Re: format/write question
am 17.08.2007 01:43:22 von Darren Dunham
Steve K. wrote:
> #!/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.
--
Darren Dunham ddunham@taos.com
Senior Technical Consultant TAOS http://www.taos.com/
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
Re: format/write question
am 21.08.2007 21:42:19 von greymaus
On 2007-08-16, Darren Dunham wrote:
> 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.
>
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.
--
Greymaus
Just Another Grumpy Old man