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

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.

Replies are listed 'Best First'.
Re^5: [Re]confirm box (true false boolean context !!0 and !!1 )
by Anonymous Monk on Dec 24, 2014 at 11:07 UTC

    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