Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: [Re]confirm box

by Anonymous Monk
on Dec 24, 2014 at 06:45 UTC ( [id://1111272]=note: print w/replies, xml ) Need Help??


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

Might be cleaner

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

Replies are listed 'Best First'.
Re^4: [Re]confirm box
by Anonymous Monk on Dec 24, 2014 at 10:20 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). 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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1111272]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-24 13:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found