Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

... and in addition to Template::Toolkit and the other fine and dandy modules out there ... you might consider the fine and dandy language known as "perl" (aka "Perl", aka "PERL"). (Who woulda imagined it!)

Straight out of the box, you can write perl code that "cleans up" all that code you have inherited, and encourages all that great stylesheet conformity, and all that great MVC separation, and whips up a hot batch of any other buzzword-soup-of-the-day you may want to serve up.

Here is an example that is all plain perl code (with one added subroutine) that keeps our HTML template looking more like HTML than like perl (instead of the other way around).

### begin_: init perl use strict; use warnings; ### begin_: init vars my $sOut; my $oAlph = [('A' .. 'Z')]; my $oSubj = {}; $oSubj->{A} = [qw(africa asia)]; $oSubj->{B} = [qw(belgium brazil )]; my $oArti = {}; $oArti->{africa} = [qw(afone aftwo afthree )]; $oArti->{asia} = [qw(asone astwo )]; $oArti->{belgium} = [qw(beone)]; $oArti->{brazil} = [qw(brone)]; ### begin_: OutputTemplate ### ------------------ ### ------------------ $sOut .= " <html> <head></head> <body> " .sLoop($oAlph,sub{ "<a href='#'>$_</a> || " }) ."<hr /> " .sLoop([keys %{$oSubj}],sub{my $sLett=$_; "<h2>$sLett</h2> " .sLoop($oSubj->{$sLett},sub{my $sName=$_; "<h3>$sName</h3> " .sLoop($oArti->{$sName},sub{ "<h4>$_</h4> " }) }) }) . " </body> <html> " ; ### ------------------ ### ------------------ print $sOut; ### begin_: subroutines ### Simple Looping subroutine ### we use to make the perl code in our ### output template more compact sub sLoop { join"",map{$_[1]->();} (@{$_[0]}) }###end_sub ### begin_: end perl 1; __END__

which gives us something akin to ...

A || B || C || D || E || F || G || H || I || J || K || L || M || N || O || P || Q || R || S || T || U || V || W || X || Y || Z ||

A

africa

afone

aftwo

afthree

asia

asone

astwo

B

belgium

beone

brazil

brone


In reply to Re: Building html site maps by dimar
in thread Building html site maps by wfsp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-23 07:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found