Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: using format to align

by SysApe9000 (Acolyte)
on Mar 27, 2003 at 16:48 UTC ( [id://246286]=note: print w/replies, xml ) Need Help??


in reply to using format to align

I would highly recommend you avoid using FORMAT in favor of learning printf()/sprintf(). printf() is available in many languages so you might find that knowing it is worth the effort.

Also, I think I've read that FORMAT is on the way out... but I couldn't find any mention of it in a brief search so YMMV.

Try: perldoc -f printf to get started.

Replies are listed 'Best First'.
(jeffa) 2Re: using format to align
by jeffa (Bishop) on Mar 27, 2003 at 17:08 UTC
    For this problem, (s)printf indeed might be the better solution. But even if formats are "on the way out", i will still use them if they are the right fit for the problem, and sometimes they really are better than (s)printf. See Are formats in perl useful? for an interesting thread on the topic.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: Re: using format to align
by rinceWind (Monsignor) on Mar 27, 2003 at 20:58 UTC
    Just to correct a wrong impression, format is not going away completely in Perl 6. It is just leaving the core as a built-in with its own wierd syntax, and becoming a function and/or a module.

    This is documented under RFC 230. TheDamian may possibly have something more to say, as he is the author of the RFC, and is involved in the development.

      As rinceWind said (and as Larry made official in Apocalypse 6), in Perl 6 formats are being reworked under my evil influence. For a taste of what they'll be like, see the Text::Reform module.

      Using that module, your table would be generated like so:

      use Text::Reform; my @name = qw(foo foo2 foo3); my @last = qw(bar bar2 bar3); my @count = qw( 3 4 5 ); print form "--------------------------------------------------", "NAME LAST COUNT", "--------------------------------------------------", "[[[[[[[[[ [[[[[[[[[[[[[[[[[[ |||||", \@name, \@last, \@count;
      Or, if your data was likely to spill over multiple pages, you might prefer more sophisticated headers and footers:
      use Text::Reform; my @name = (qw(foo foo2 foo3)) x 20; my @last = (qw(bar bar2 bar3)) x 20; my @count = (qw( 3 4 5 )) x 20; print form { header => "--------------------------------------------------\n" . "NAME LAST COUNT\n" . "--------------------------------------------------", footer => sub { my ($pagenum, $lastpage) = @_; return "\n\n\nEND OF REPORT" if $lastpage; form "\n\n\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", ".../".($_[0]+1); }, pagelen => 20, pagefeed => "\n\n".("_"x60)."\n\n", }, "[[[[[[[[[ [[[[[[[[[[[[[[[[[[ |||||", \@name, \@last, \@count;
      Note in particular the use of a (conditional, nested) call to form within the footer of the main form.

      The Perl 6 format syntax will be even more sophisticated than that provided by Text::Reform, since I'll be taking advantage of new features of Perl 6. For example, the named options that control headers/footers/etc won't need to be in hashes, and array arguments won't require an explicit backslash.

      There will also be additional formatting modes and options, all of which will eventually be described in Exegesis 7.

Re: Re: using format to align
by Lhamo Latso (Scribe) on Mar 27, 2003 at 17:39 UTC
    If FORMAT is going away, what about the language name? Sounds like it would be PEL v1.0
      You mean somebody actually still uses formats? Whaugh, I can hardly believe it!

      Formats were obsolete from the moment variable-pitch fonts became commonplace. I write my reports, if you can call them that, to text-separated files, Excel spreadsheets, or HTML tables. I've never ever used formats in my 8 years of intensive use of Perl, and I'm not planning on ever using them, either.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://246286]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-19 22:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found