Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

•Re: Annotating Files

by merlyn (Sage)
on Apr 18, 2002 at 01:04 UTC ( #160066=note: print w/ replies, xml ) Need Help??


in reply to Annotating Files

You can keep the template right inside the program, and do the medium lifting with Template instead of Perl, like so:

my %d; while (<DATA>) { my ($file, $line, $comment) = /^([^:]+):(\d+)\s+(.*)/ or warn("unknown line, skipping: $_"), next; push @{$d{$file}{$line}}, $comment; } use Template; Template->new->process(\<<'EOT', { d => \%d, env => \%ENV }) [%# USE Dumper; Dumper.dump(d); -%] [%- FOREACH filek = d.keys.sort; filev = d.$filek; FOREACH linek = filev.keys.nsort; linev = filev.$linek; "<dt>$filek</dt><dd><b> line $linek</b>\n"; FOREACH comment = linev; " <ul>\n" IF loop.first; " <li>"; comment | html; "</li>\n"; " </ul>\n" IF loop.last; END; "</dd>\n"; END; END; -%] EOT or die Template->error; __END__ comment_tmpl.tt2:1 This would be more readable if I turned on Template +'s space-stripping options. comment_reader.pl:31 More informative error message would probably be +good. comment_reader.pl:71 Need a better explanation of data structure. annotate.el:1 Should properly be in a mode... annotate.el:11 Should be configurable variable annotate.el:13 Formatting should be configurable in variable annotate.el:11 Should automatically make "annotations" visible if it i +sn't already annotate.el:21 Control-c keys are supposed to be for mode-specifics...
which generates:
annotate.el
line 1
  • Should properly be in a mode...
annotate.el
line 11
  • Should be configurable variable
  • Should automatically make "annotations" visible if it isn't already
annotate.el
line 13
  • Formatting should be configurable in variable
annotate.el
line 21
  • Control-c keys are supposed to be for mode-specifics...
comment_reader.pl
line 31
  • More informative error message would probably be good.
comment_reader.pl
line 71
  • Need a better explanation of data structure.
comment_tmpl.tt2
line 1
  • This would be more readable if I turned on Template's space-stripping options.

-- Randal L. Schwartz, Perl hacker


Comment on •Re: Annotating Files
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2014-07-24 09:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (158 votes), past polls