Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Best practices and any way to have Perl Tidy clean it up

by talexb (Canon)
on Apr 14, 2013 at 21:04 UTC ( #1028648=note: print w/ replies, xml ) Need Help??


in reply to Best practices and any way to have Perl Tidy clean it up

I have my own preferences on how SQL should get tidied up, and what you have is close. However, you probably shouldn't expect perltidy to handle SQL as well as Perl. I'd run perltidy on the code, then go back and organize the SQL separately.

And my preference for formatting this chunk would be

my $sth = $dbh->prepare(" SELECT t.id, t.emp_name, t.emp_email, t.req_status, t.date_requested, t.mngr_email, t.date_submitted, ( SELECT GROUP_CONCAT ( ( CASE WHEN req_status = 'Approved' THEN emp_name END ) SEPARATOR ', ' ) FROM requests s WHERE s.date_requested = t.date_requested ) AS approved FROM requests t WHERE req_status = 'Pending' AND mngr_email = '$filter' AND date_requested >= '$date' ORDER BY emp_name, date_requested ");
This format highlights all of the key words, leaves spaces between each of the resulting columns, indents the 'AND' clauses to clarify the filtering, and generally exposes as much of the logic behind the query as possible.

There is no one right way to format SQL, but this approach seems fairly clear.

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds


Comment on Re: Best practices and any way to have Perl Tidy clean it up
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2014-09-23 03:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (210 votes), past polls