Dr. Poo wrote:
I'm trying to declare a variable $log that is a reference to an array that will contain the small amounts of data that need to be logged throughout a backup script i'm working on. I'd like to declare this scalar reference in the BEGIN function, but i can't use it outside of the BEGIN function if i declare 'my $log' in BEGIN.perldoc -f our (depending on your version) taht will make it package scoped rather than block scoped.
Hmmm.... And since BEGIN is the first function to be called (right??) how might i declare the scalar as global?Not exactly. BEGIN isn't really a function, it is just a block identifier that tells the compiler to do things up front rather than at run time.
Well, actually, i just tried 'use vars qw($log)' and it seems to have solved that problem.
This is very similar to what 'our' does.
But! i also have a function being used to assign the reference to $log that will point to the log array, and it ?needs? to be prototyped before the call is made to it... and i just tried 'use subs qw(StartLog(...))' but it claims it still needs to be prototyped before the call.. i think.This I believe is trying to get the return value of the sub, rather than declaring it. If the sub is in a package that you have already used it should be available at compile time, as use is a compile time process, but order does matter. It would seem to do things in the above manner you would have to define or at least declare the sub in a BEGIN before the 'use'.
Any ideas?
I get this error after a call is made within BEGIN like such
# START PERL CODE
use strict;
use warnings;
use vars qw($log);
use subs qw(&StartLog(...));
In general you should not need the '&' when calling a sub, if you get strict complaining about barewords, blah blah blah then tack on () to the end of the sub rather than the &...
...
...
BEGIN
{
$log = &StartLog(...);
...
}
...
...
# END PERL CODE
(here's the error..)
Undefined subroutine &main::StartLog called at localMysqlHotCopyToRemote.pl
line 349.
BEGIN failed--compilation aborted at localMysqlHotCopyToRemote.pl line 357.
If anyone could briefly explain what the differences are between calling a sub-routine with the amperstand '&' and without it. I remember reading about it somewhere... Does it have to do with my problem?
from perldoc perlsub:
"To call subroutines:
NAME(LIST); # & is optional with parentheses.
NAME LIST; # Parentheses optional if predeclared/imported.
&NAME(LIST); # Circumvent prototypes.
&NAME; # Makes current @_ visible to called subroutine."
HTH,
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]