Rosetta Code/Find bare lang tags

Revision as of 04:05, 9 July 2011 by rosettacode>CRGreathouse (new draft task)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Find all <lang> tags without a language specified in the text of a page. Display counts by language section:

Rosetta Code/Find bare lang tags is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Description

<lang>Pseudocode</lang>

=={{header|C}}==
<lang C>printf("Hello world!\n");</lang>

=={{header|Perl}}==
<lang>print "Hello world!\n"</lang>

should display something like

2 bare language tags.

1 in perl
1 in no language

For extra credit, allow multiple files to be read. Summarize all results by language:

5 bare language tags.

2 in c ([[Foo]], [[Bar]])
1 in perl ([[Foo]])
2 in no language ([[Baz]])

Perl

<lang perl>my $lang = 'no language'; my $total = 0; my %blanks = (); while (<>) {

 if (m/<lang>/) {
   if (exists $blanks{lc $lang}) {
     $blanks{lc $lang}++
   } else {
     $blanks{lc $lang} = 1
   }
   $total++
 } elsif (m/==\s*Template:\s*header\s*\\s*==/) {
   $lang = lc $1
 }

}

if ($total) { print "$total bare language tag" . ($total > 1 ? 's' : ) . ".\n\n"; while ( my ($k, $v) = each(%blanks) ) { print "$k in $v\n" } }</lang>