Rosetta Code/Fix code tags: Difference between revisions

From Rosetta Code
Content added Content deleted
(Undo revision 21864 by GugaTagFixer (Talk))
m (→‎{{header|Perl}}: Changed list of single-quoted strings to qw(…) list.)
Line 14: Line 14:
=={{header|Perl}}==
=={{header|Perl}}==
<lang perl>
<lang perl>
my @langs = ('ada', 'cpp-qt', 'pascal', 'lscript', 'z80', 'visualprolog',
my @langs = qw(ada cpp-qt pascal lscript z80 visualprolog
'html4strict', 'cil', 'objc', 'asm', 'progress', 'teraterm', 'hq9plus',
html4strict cil objc asm progress teraterm hq9plus genero tsql
'genero', 'tsql', 'email', 'pic16', 'tcl', 'apt_sources', 'io', 'apache',
email pic16 tcl apt_sources io apache vhdl avisynth winbatch
'vhdl', 'avisynth', 'winbatch', 'vbnet', 'ini', 'scilab', 'ocaml-brief',
vbnet ini scilab ocaml-brief sas actionscript3 qbasic perl bnf
cobol powershell php kixtart visualfoxpro mirc make javascript
'sas', 'actionscript3', 'qbasic', 'perl', 'bnf', 'cobol', 'powershell',
cpp sdlbasic cadlisp php-brief rails verilog xml csharp
'php', 'kixtart', 'visualfoxpro', 'mirc', 'make', 'javascript', 'cpp',
actionscript nsis bash typoscript freebasic dot applescript
'sdlbasic', 'cadlisp', 'php-brief', 'rails', 'verilog', 'xml', 'csharp',
haskell dos oracle8 cfdg glsl lotusscript mpasm latex sql klonec
'actionscript', 'nsis', 'bash', 'typoscript', 'freebasic', 'dot',
ruby ocaml smarty python oracle11 caddcl robots groovy smalltalk
'applescript', 'haskell', 'dos', 'oracle8', 'cfdg', 'glsl', 'lotusscript',
diff fortran cfm lua modula3 vb autoit java text scala
'mpasm', 'latex', 'sql', 'klonec', 'ruby', 'ocaml', 'smarty', 'python',
lotusformulas pixelbender reg _div whitespace providex asp css
'oracle11', 'caddcl', 'robots', 'groovy', 'smalltalk', 'diff', 'fortran',
lolcode lisp inno mysql plsql matlab oobas vim delphi xorg_conf
'cfm', 'lua', 'modula3', 'vb', 'autoit', 'java', 'text', 'scala',
gml prolog bf per scheme mxml d basic4gl m68k gnuplot idl abap
'lotusformulas', 'pixelbender', 'reg', '_div', 'whitespace', 'providex',
intercal c_mac thinbasic java5 xpp boo klonecpp blitzbasic eiffel
'asp', 'css', 'lolcode', 'lisp', 'inno', 'mysql', 'plsql', 'matlab',
povray c gettext);
'oobas', 'vim', 'delphi', 'xorg_conf', 'gml', 'prolog', 'bf', 'per',
'scheme', 'mxml', 'd', 'basic4gl', 'm68k', 'gnuplot', 'idl', 'abap',
'intercal', 'c_mac', 'thinbasic', 'java5', 'xpp', 'boo', 'klonecpp',
'blitzbasic', 'eiffel', 'povray', 'c', 'gettext');


my $slang = '/lang';
my $slang = '/lang';

Revision as of 17:37, 17 February 2009

Task
Rosetta Code/Fix code tags
You are encouraged to solve this task according to the task description, using any language you may know.

Fix Rosetta Code deprecated code tags, with these rules:

Change <%s> to <lang %s>
Change </%s> to </lang>
Change <code %s> to <lang %s>
Change </code> to </lang>

Usage:

cat wikisource.txt | ./convert.py > converted.txt

Perl

<lang perl> my @langs = qw(ada cpp-qt pascal lscript z80 visualprolog html4strict cil objc asm progress teraterm hq9plus genero tsql email pic16 tcl apt_sources io apache vhdl avisynth winbatch vbnet ini scilab ocaml-brief sas actionscript3 qbasic perl bnf cobol powershell php kixtart visualfoxpro mirc make javascript cpp sdlbasic cadlisp php-brief rails verilog xml csharp actionscript nsis bash typoscript freebasic dot applescript haskell dos oracle8 cfdg glsl lotusscript mpasm latex sql klonec ruby ocaml smarty python oracle11 caddcl robots groovy smalltalk diff fortran cfm lua modula3 vb autoit java text scala lotusformulas pixelbender reg _div whitespace providex asp css lolcode lisp inno mysql plsql matlab oobas vim delphi xorg_conf gml prolog bf per scheme mxml d basic4gl m68k gnuplot idl abap intercal c_mac thinbasic java5 xpp boo klonecpp blitzbasic eiffel povray c gettext);

my $slang = '/lang';

my $text = do { local $/; <STDIN> };

foreach my $i (@langs) {

   $text =~ s|<$i>|<lang $i>|g;
   $text =~ s|</$i>|<$slang>|g;

}

$text =~ s|(.*?)|<lang \1>\2<$slang>|sg;

print $text; </lang>

Python

<lang python>

  1. coding: utf-8

import sys import re

langs = ['ada', 'cpp-qt', 'pascal', 'lscript', 'z80', 'visualprolog', 'html4strict', 'cil', 'objc', 'asm', 'progress', 'teraterm', 'hq9plus', 'genero', 'tsql', 'email', 'pic16', 'tcl', 'apt_sources', 'io', 'apache', 'vhdl', 'avisynth', 'winbatch', 'vbnet', 'ini', 'scilab', 'ocaml-brief', 'sas', 'actionscript3', 'qbasic', 'perl', 'bnf', 'cobol', 'powershell', 'php', 'kixtart', 'visualfoxpro', 'mirc', 'make', 'javascript', 'cpp', 'sdlbasic', 'cadlisp', 'php-brief', 'rails', 'verilog', 'xml', 'csharp', 'actionscript', 'nsis', 'bash', 'typoscript', 'freebasic', 'dot', 'applescript', 'haskell', 'dos', 'oracle8', 'cfdg', 'glsl', 'lotusscript', 'mpasm', 'latex', 'sql', 'klonec', 'ruby', 'ocaml', 'smarty', 'python', 'oracle11', 'caddcl', 'robots', 'groovy', 'smalltalk', 'diff', 'fortran', 'cfm', 'lua', 'modula3', 'vb', 'autoit', 'java', 'text', 'scala', 'lotusformulas', 'pixelbender', 'reg', '_div', 'whitespace', 'providex', 'asp', 'css', 'lolcode', 'lisp', 'inno', 'mysql', 'plsql', 'matlab', 'oobas', 'vim', 'delphi', 'xorg_conf', 'gml', 'prolog', 'bf', 'per', 'scheme', 'mxml', 'd', 'basic4gl', 'm68k', 'gnuplot', 'idl', 'abap', 'intercal', 'c_mac', 'thinbasic', 'java5', 'xpp', 'boo', 'klonecpp', 'blitzbasic', 'eiffel', 'povray', 'c', 'gettext']

slang = '/lang'

text = sys.stdin.read()

for i in langs:

   text = text.replace("<%s>" % i,"<lang %s>" % i)
   text = text.replace("</%s>" % i, "<%s>" % slang)

text = re.sub("(?s)(.*?)", r"<lang \1>\2<%s>" % slang, text)

sys.stdout.write(text) </lang>