Okay sure, I just said that because it's strange to see all those print() and \n to output strings with embeddeded code. It just doesn't look nice visually (and probably not fun to debug if javascript gets big or halfway complicated).

Yup, using double quoted strings for everything is just a sign of being very new :) ... and skipping perlintro/perlquote

Another example of cgi101 , stuffing stuff inside subs is the idea, see sub RootPage, sub RootTemplate , ... and unclunky cgi and esp Re^5: I need help with displaying newline or paragraph using perl on my website (pass arguments more subs)

so the OP might write

sub checkform_js { return q{ function CheckForm_onclick() { var myForm = document.form1; var message = ""; message = "Confirm if you need to disable . Choose OK to go ah +ead and Cancel to abort."; var answer = confirm(message); if (answer == false ){ document.write('You chose to Cancel. Closed window.'); } else { document.getElementById("userresponse").value = "Yes"; document.form.submit(); } } }; } ## end sub checkform_js sub main_page { my( $title ) = @_; return '<html> <head> <LANGUAGE=Javascript> <script>', checkform_js(), '</SCRIPT> <title>', $title, '</title> </head> <body onload="return (CheckForm_onclick())"> <FORM action="disable.cgi" method="post"> <input type="hidden" name="userresponse" > </form> </body> </html> '; } ## end sub main_page

Thats not best way to write js either, but one thing at a time :)

One thing I don't understand in the example you linked though... Why did he use this double negation construction in the ValidLogin() sub: It seems redundant? Actually why even use any ! operators at all and just return the literal code you intend.

Well, its not a code, its a boolean, it forces boolean context, returns the true false "constants", see Re: Anybody use !!, Context tutorial

so its not good to pretend like its a code when its boolean -- in practice it doesn't really matter to perl, but in reading code it makes intent clear, its self documenting


In reply to Re^5: [Re]confirm box (true false boolean context !!0 and !!1 ) by Anonymous Monk
in thread [Re]confirm box by kbee

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.