in reply to Re: A question of style.
in thread A question of style.
Which, IMHO, is much more easy to read. (Notice the removal of the second for() loop, as the two loops simply did the same thing. Style is not a replacement for sensible coding :-)my $action = param("ACTION") || "NONESUCH"; #Bond the built-in and accessory components to the parent. if($action eq "BOND") { my $main = param("MAIN"); my @built = param("BUILT"); my @acc = param("ACC"); my $query = "SELECT location FROM demstock2 WHERE ds_id=?"; my $sth = $db->prepare($query); $sth->execute($main) or print "Can't execute <pre>$query</pre>: " . $db->er +rstr . "<br>\n"; my $mainlocation = $sth->fetchrow_hashref; $sth->finish(); if($mainlocation->{"location"} ne "STOCK") { print b("Refusing to bond items to $main, as it isn't +in free stock") . br(); } else { for my $child (@built, @acc) { #Find out if it still is in free stock my $query = "SELECT curr_parent_id FROM demsto +ck2 WHERE ds_id=?"; my $sth = $db->prepare($query); $sth->execute($child) or print "Can't execute $query: " . $s +th->errstr . "<br>\n"; my $current_status = $sth->fetchrow_hashref; $sth->finish(); if($current_status->{"curr_parent_id"} != 0) { print "Refusing to modify the status o +f demstock $child. It has already been moved<br>\n"; next; } #Move the kit, and update the action table my $move_query = "UPDATE demstock2 SET curr_pa +rent_id=? WHERE ds_id=?"; my $move_sth = $db->prepare($move_query); $move_sth->execute($main, $child) or print "Can't execute <PRE>$move_que +ry</PRE>: " . $sth->errstr . br(); $move_sth->finish(); my $action_query = "INSERT INTO action "; $action_query .= "(action_id, action_type, d +s_id, occurred, ref_no, staff_id) VALUES"; $action_query .= "(NULL, 'MOVE', ? +, CURRENT_TIMESTAMP, ?, ?)"; my $action_sth = $db->prepare($action_query) +; $action_sth->execute($child, "0,$main", $calus +er) or print "Can't execute <PRE>$action_q +uery</PRE>: " . $sth->errstr . br(); $action_sth->finish; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: A question of style.
by Masem (Monsignor) on Oct 30, 2001 at 21:48 UTC | |
|
Re: Re: Re: A question of style.
by tommyw (Hermit) on Oct 30, 2001 at 21:26 UTC |