The quick answer is perldiag. If you still want just what you asked for -- a list of warnings by category, try the following one-liner:
perl -MData::Dumper -ne '$item=$1 if /^=item (.*)/; push @{$warnings{$1}}, $item if /\(W ([^)]*)\)/; END {print Dumper \%warnings}' /usr/share/perl/5.8/pod/perldiag.pod
(Make sure to adjust the location of perldiag as approprate to your system -- perldoc -l perldiag will show you where it is.)
You want to know how it works? Well, let's start by showing you the code that I left out (IE that the -n option implies). The simpilest way to do this, and to do some reformatting at the same time, is to use -MO=Deparse, as in perl -MO=Deparse,-p -MData::Dumper -ne '$item=$1 if /^=item (.*)/; push @{$warnings{$1}}, $item if /\(W ([^)]*)\)/; END {print Dumper \%warnings}'
That gives:
use Data::Dumper;
LINE: while (defined($_ = <ARGV>)) {
$item = $1 if /^=item (.*)/;
push @{$warnings{$1};}, $item if /\(W ([^)]*)\)/;
sub END {
print Dumper(\%warnings);
}
;
}
, which isn't quite readable. I'll change some things around to make it a bit more idiomatic.
use Data::Dumper;
while (defined($_ = <ARGV>)) {
if (/^=item (.*)/) {
$item = $1;
}
if (/\(W ([^)]*)\)/) {
push @{$warnings{$1}}, $item;
}
}
print Dumper(\%warnings);
I got rid of some superflous semicolons, the unused label LINE, and changed FOO if BAR to if (BAR) {FOO}. Most importantly, I moved the sub END { } bit to where it actually gets run -- as the program is ending.
But it still doesn't do some things you shouldn't do in any program longer then one line, even though it's no longer a one-liner -- it needs warnings and strict.
use Data::Dumper;
use warnings;
use strict;
my ($item, %warnings);
while (defined($_ = <ARGV>)) {
if (/^=item (.*)/) {
$item = $1;
}
if (/\(W ([^)]*)\)/) {
push @{$warnings{$1}}, $item;
}
}
print Dumper(\%warnings);
So, now that we've changed it from a confusing little oneliner to a real program, can you figure out how it works? It runs through each line of the file provided on the command line, or standard input if none was given. If the line starts with =item and a space, we save the rest of the line in the variable $item for later. If it contains a begin-paren, followed by a W, a space, a bunch of non-parenthesis characters, and then an end paren, then we add the contents of $item to the end of the array-reference @{ ... } given in the slot of %warnings given by $1 (the bunch of non-parenthesis characters from the line we're on). Then, once we're finished with all the lines in the ARGV filehandle, we dump out %warnings.
Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).
|