On Thursday 20 May 2010 13:52:58 HACKER Nora wrote:
> 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.
> 

From a cursory look at your program, it seems that you can just set up $mode 
as a global variable, and keep it at that instead of just passing it around. 
Alternatively, maybe you'd like to define a class and keep the mode variable 
there as a property of the class' instances.

> Script (concentrated):
> =================
> 
> #!/usr/bin/perl
> use strict;
> use warnings;
> 
> my $mode = ARGV[0];

That should be "my $mode = $ARGV[0];" or preferably "my $mode = shift(@ARGV);" 
or "my ($mode) = @ARGV;".

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
"The Human Hacking Field Guide" - http://shlom.in/hhfg

God considered inflicting XSLT as the tenth plague of Egypt, but then
decided against it because he thought it would be too evil.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to