HACKER Nora <nora.hac...@stgkk.at> wrote: > Obviously, my point wasn't clear enough, I'm sorry for that. The > variable in the code extract that I'm really bothering about is the > $sdb: It is needed in the SWITCH of a sub-function, but this construct > only works if I pre-declare the $sdb in the calling function backup(), > even if it isn't needed for a $mode eq "b" but only for "r".
Let's see if I understand this correctly: You have a global variable $mode that's deciding the mode of operation in your sub dblog(), to quote: > # DBLOG sub-function > sub dblog { > my ( $backup, $dbvers, $sdb ) = @_; > SWITCH: { > ( $mode eq "b" ) && do { > print $fh_dblogsql "insert into dbmovelog (DEBENAME, MOVE, > FELD1, FELD2, ERSTELL_TS) values ('".$db."', '".$mode."', '".$backup."', > '".$dbvers."', sysdate);"; > last SWITCH; > }; > ( $mode eq "t" ) && do { > print $fh_dblogsql "insert into dbmovelog (DEBENAME, MOVE, > FELD1, FELD2, ERSTELL_TS) values ('".$db."', '".$mode."', '".$sdb."', > sysdate);"; > last SWITCH; > }; > } >} Depending on the value of $mode, you run two slightly different SQL statements. The second of them with the wrong number of values ;-) >From the look of things, $backup and $sdb are really the same thing, namely >input for the column FELD1. My gut feeling is that you should pass $mode as an argument to the function since it's never nice to have a subroutine that does two different things without an obvious reason. I'd then coalesce $backup and $sdb into the variable $feld1 and suddenly you don't need your "switch" anymore. Apart from that, there's really no need to call a three argument function with three arguments when you know you don't need the third argument. Just call it with two arguments in that case, and the troublesome variable will be set to undef. HTH, Thomas -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/