Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

... I'm stuck ...

Write more functions, determine the common parts and turn them into functions, then turn the non-common parts into functions , so you have small functions you can understand

#!/usr/bin/perl -- use strict; use warnings; Main( @ARGV ); exit( 0 ); sub Show_Red_HTML { my( $query ) = @_; my $dirname = '.'; my $js_includes = js_includes(); my $css_includes = stylesheet_includes(); my $title = "This is the redness"; my $drops = red_dropdown_files( $dirname ); my $body = red_form_html( $query, $drops ); return Show_HTML( "$css_includes $js_includes", $title, $body ); } ## end sub Show_Red_HTML sub Show_HTML { my( $head, $title, $body ) = @_; my $header = common_body_header_html(); my $footer = common_body_footer_html(); return qq{<!DOCTYPE html> <html> <head> <title> $title </title> $head </head> <body> $header $body $footer </body> </html>}; } ## end sub Show_HTML sub red_dropdown_files { my( $dirname ) = @_; use Path::Tiny qw/ path cwd /; use CGI qw/ escapeHTML /; my @files = path( $dirname )->children; my $ret = ""; for my $file ( @files ) { $ret .= sprintf qq{<option value="%s">%s</option>\n}, escapeHTML( $file ), escapeHTML( $file ); } return $ret; } ## end sub red_dropdown_files

Why write like this? Its easier to test/debug each small part seperately , for example

sub Main { Tests(); # RealProgram(); } ## end sub Main sub Tests { require Test::More; Test::More->import( 'no_plan' ); ## and ok()... test_drops(); } ## end sub Tests sub test_drops { chdir 'testdir'; my $drops = red_dropdown_files( '.' ); ok( int $drops =~ m{\Q<option value="chapter-8.pdf">\E}, 'drops wo +rks' ); } ## end sub test_drops

Its important not to forget to escapeHTML

In reply to Re: HTML/CGI for loop problem by Anonymous Monk
in thread HTML/CGI for loop problem by Jabox

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?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2023-10-03 06:59 GMT
Find Nodes?
    Voting Booth?

    No recent polls found