Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Monks,

This may be a bit rambling, but I was thinking about the Report part of Practical Extraction and Report Language today. I looked at perlform, and wondered why I don't see these features in use more often.

I started thinking about this after writing a small script that found the latest revision number of a set of .c and .h files and printed them to STDOUT. I ended up with this:

#! /usr/bin/perl use strict; use File::Find; my ( $filename, $revision, $date ); format STDOUT = @<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @>>>>>>>>> | @>>>>>>>>>> $filename, $revision, $date . find( \&wanted, "." ); sub wanted { if( /[hc]$/ ) { open( FILE, $_ ) or do { warn "Could not open ".$_; return }; $date = "Not Found"; $revision = "Not Found"; while( my $line = <FILE> ) { # This is the comment line I was after # * | A | 12.01.99 | developer@company.com | if( $line =~ /^\s*\*\s*\|\s*([A-Z])\s*\|\s*([^\s]+)/ ) { $revision = $1; $date = $2; } } $filename = $File::Find::name; write; close FILE; } }

It's a quick and dirty hack that uses File::Find to find all .c and .h files below the current directory, and a regular expression to fetch some fields from the header comments. The match results are then stuffed into the predefined values that are defined in the format, and then write pushes it all out to STDOUT.

Why is the use of format so seldom seen around here at the Monastery? Is it because of the rather arcane picture syntax, or perhaps because printf and friends are simpler to use? Or something else entirely?

I find that I like formats, though. Different. Declarative. Quite concise. Good :)

pernod
--
Mischief. Mayhem. Soap.


In reply to Do you use format and write? by pernod

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (4)
    As of 2019-09-18 06:54 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      The room is dark, and your next move is ...












      Results (223 votes). Check out past polls.

      Notices?