in reply to write html code with perl
G'day lenieto3,
I created an images directory with these dummy files:
asd_fgh_jkl.png qwerty.png uiop.png zxcv_bnm.png
This script:
#!/usr/bin/env perl use strict; use warnings; my $ul = 0; while (<DATA>) { $ul = 0 if /<\/ul>/; next if $ul; print; if (/<ul>/) { $ul = 1; for (glob 'images/*.png') { my @name = map { "\u$_" } split /_/ => (/images\/(.+)\.png +/)[0]; print qq{ <li><a target="_blank" href="$_">@nam +e</a></li>\n}; } } } __DATA__ <html> <head> <link type="text/css" rel="stylesheet" href="style/stylesheet. +css"/> <title>mchtd.info</title> </head> <body> <ul> <li><a target="_blank" href="images/patecumbia.png">Patecu +mbia</a></li> <li><a target="_blank" href="images/trapped.png">Trapped</ +a></li> <li><a target="_blank" href="images/navaja_force.png">Nava +ja Force</a></li> <li><a target="_blank" href="images/que_esta_pasando.png"> +¿Qué está pasando?</a></li> <li><a target="_blank" href="images/the_look.png">The Look +</a></li> <li><a target="_blank" href="images/hablame.png">Hablame</ +a></li> </ul> </body> </html>
Produced this output:
<html> <head> <link type="text/css" rel="stylesheet" href="style/stylesheet. +css"/> <title>mchtd.info</title> </head> <body> <ul> <li><a target="_blank" href="images/asd_fgh_jkl.png">Asd F +gh Jkl</a></li> <li><a target="_blank" href="images/qwerty.png">Qwerty</a> +</li> <li><a target="_blank" href="images/uiop.png">Uiop</a></li +> <li><a target="_blank" href="images/zxcv_bnm.png">Zxcv Bnm +</a></li> </ul> </body> </html>
That's pretty much what you want except for link names like "¿Qué está pasando?": you'd need to set up rules for those; if there's only a few, manual editing may be less effort than writing the code.
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: write html code with perl
by graff (Chancellor) on Mar 01, 2014 at 09:11 UTC | |
by kcott (Archbishop) on Mar 01, 2014 at 18:32 UTC |