Forum Webscript.Ru
Программирование => Perl => Тема начата: Troum от 25 Ноября 2004, 01:30:32
-
Возникла следующая проблема
есть головной скрипт:
use strict;
use MyModule;
our $our_var;
.....
redirect($name);
и соответственно модуль MyModule;
package MyModule;
use strict;
our $our_var;
....
sub redirect(){
my $name = shift;
require $name;
run();
}
Саб run() подгружаемого модуля оперирует с глобальной переменной $our_var. Однако она становиться undef (тоже и для MyModule::redirect()).
Подскажите, в чем ошибка
-
Решение было найдено добавлением в MyModule.pm строки:
*our_var = *main::our_var;
Все заработало, однако я получил варнинг:
Name "main::our_var" used only once: possible typo. Name "MyModule::our_var" used only once: possible typo
Как бы избавиться от него?
-
perldoc perldiag
Name "%s::%s" used only once: possible typo
(W once) Typographical errors often show up as unique
variable names. If you had a good reason for having a
unique name, then just mention it again somehow to
suppress the message. The "our" declaration is pro
vided for this purpose.
NOTE: This warning detects symbols that have been used
only once so $c, @c, %c, *c, &c, sub c{}, c(), and c
(the filehandle or format) are considered the same; if
a program uses $c only once but also uses any of the
others it will not trigger this warning.
-
Ок. при добавлении строки:
our $our_var;
вторая часть варнинга исчезает
Но, как правильно избавиться от
Name "main::our_var" used only once: possible typo
?