in reply to Re: [Re]confirm box
in thread [Re]confirm box

Might be cleaner to put all the javascript code inside __DATA__ section, then just open it, and loop through readline/print to display on stdout?

Replies are listed 'Best First'.
Re^3: [Re]confirm box
by Anonymous Monk on Dec 24, 2014 at 06:45 UTC

    Might be cleaner

    Not really :) The ultimate in clean is using well named subroutines that seperate code/logic from templates ... its cgi101

      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). One thing I don't understand in the example you linked though... Why did he use this double negation construction in the ValidLogin() sub:

      return !!1 if $user eq $pass; return !!0;

      It seems redundant? Actually why even use any ! operators at all and just return the literal code you intend. I can sort of see doing this for exit() to the shell, because the shell exit codes are backwards from Perl. An exit code 0 means success, whereas inside Perl program boolean 0 is false.

        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

        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