
FishMonger
Veteran
Feb 22, 2009, 10:25 AM
Post #10 of 11
(3305 views)
|
|
Re: [cuboidgraphix] Help with parse words please.
[In reply to]
|
Can't Post
|
|
For the most part, that's pretty good. However, you could tweak it a little if you really want to follow the guidelines of Best Practices. Vars should be declared not only in the smallest scope, but where they're needed without duplication. e.g.,
my($host,$database,$usr,$pwd,$dsn,$dbh,$sth,$query); $host = 'localhost'; $database = 'db'; $usr = 'USR'; $pwd = 'PWD'; Best Practice would be:
my $host = 'localhost'; my $database = 'db'; my $usr = 'USR'; my $pwd = 'PWD'; ... ... ... Your db connect statement should include a die statement. As much as possible, the line lengths should be kept below 80 col/chars (72 or below is ideal). If a statement is above that "limit", then break it up into multiple lines and long lists, such as your var assignments when parsing the line, should be put into col/row format. Which means this:
my ($TIME,$Catmp,$Lorig,$Torig,$ToAnn,$Cpocc,$Conctr,$OAvgDel,$O95,$PAvgDel,$P95,$BAvgDel,$B95,$RTrip, $Origdeny,$Inefdeny,$CPloovfl,$CPsuic,$CPtrap,$LCMdtsr,$LMdtsr) = (quotewords('[\s]+', 0, $data))[3,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47]; would become:
my ($TIME, $Catmp, $Lorig, $Torig, $ToAnn, $Cpocc, $Conctr, $OAvgDel, $O95, $PAvgDel, $P95, $BAvgDel, $B95, $RTrip, $Origdeny, $Inefdeny, $CPloovfl, $CPsuic, $CPtrap, $LCMdtsr, $LMdtsr ) = (quotewords('[\s]+', 0, $data))[3,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47]; but even that would need to be tweaked a little more. Personally, I'd probably put that data into an array instead of the individual scalars and use place holders in the prepare statement. The prepare and execute statements should include error checking.
|