format/write question

Discussion in 'Perl Misc' started by Steve K., Aug 16, 2007.

  1. Steve K.

    Steve K. Guest

    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
     
    Steve K., Aug 16, 2007
    #1
    1. Advertising

  2. 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
    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. >
     
    Darren Dunham, Aug 17, 2007
    #2
    1. Advertising

  3. Steve K.

    Guest

    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
     
    , Aug 21, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Candy
    Replies:
    2
    Views:
    1,179
    Janaka
    Feb 18, 2004
  2. Andy
    Replies:
    7
    Views:
    6,297
    Roedy Green
    May 10, 2004
  3. shannon
    Replies:
    1
    Views:
    8,618
  4. shannon
    Replies:
    0
    Views:
    582
    shannon
    Feb 1, 2006
  5. Replies:
    6
    Views:
    474
    Thomas Ganss
    Jan 15, 2006
Loading...

Share This Page