Hello,

I have a programme for database backup / recovery / some other tasks
with several modes (e.g. <b>ackup etc.) in wich a certain function is
called. In this function I do a SWITCH, depending on the mode that the
main programme is started with. In one of the cases of SWITCH (e.g.
<r>ecovery) I use a variable which may not be passed when calling the
function because it is not set for that mode. Nevertheless I get an
error when trying to run the script ("Global symbol XXX requires
explicit package name..."). My workaround so far was to declare that
variable immediately before calling the function (empty / <zero> / "")
and passing it thus although it isn't needed actually.

Script (concentrated):
=================

#!/usr/bin/perl
use strict;
use warnings;

my $mode = ARGV[0];

###################
# 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;
            };
        }
}

###################
# BACKUP function
sub backup {
    my ($mode) = @_;
    my $db = <STDIN>;
    my $dbvers = getDBVersion();
    my $backup = $db . '_' . $dbvers . '_' . `/bin/date +%y%m%d-%H%M%S`;
    my $sdb;
    dblog( $backup, $dbvers, $sdb );
}

###################
# MAIN programme
SWITCH: {
    ( $mode eq "b" ) && do {
        backup($mode);
        last SWITCH;
    };
    ( $mode eq "r" ) && do {
        recover($mode);
        last SWITCH;
    };
}


I guess this is not a proper way to handle such cases, is it? :-) But
what is "good practice", then? Could anybody please enlighten me?

Thanks in advance, 
Nora 



Reply via email to