PERL и use strict



#!/usr/bin/perl -w

use strict;

my ($a,$b);

sub finding{
my $distfiles;
open(MAKE_CONF,"/etc/make.conf") || die "Can't open /etc/make.conf";
foreach (<MAKE_CONF>){
my $port=$1;
print $port;
my $dist=$1;
return $port;

Global symbol "$port" requires explicit package name at ./ line 21.
Execution of ./ aborted due to compilation errors.

чё за глюки у меня?

Ответ на: Re: PERL и use strict от golodranez

Re: PERL и use strict

Вобщем, объявление my действует только в пределах скобок {}, будь то цикл, подпрограмма и т.п.

from perldoc perlsub:

Private Variables via my()


my $foo; # declare $foo lexically local
my (@wid, %get); # declare list of variables local
my $foo = "flurp"; # declare $foo lexical, and init it
my @oof = @bar; # declare @oof lexical, and init it
my $x : Foo = $y; # similar, with an attribute applied

WARNING: The use of attribute lists on "my" declarations
is still evolving. The current semantics and interface
are subject to change. See attributes and Attribute::Han-

The "my" operator declares the listed variables to be lex-
ically confined to the enclosing block, conditional
("if/unless/elsif/else"), loop ("for/fore-
ach/while/until/continue"), subroutine, "eval", or
"do/require/use"'d file. If more than one value is
listed, the list must be placed in parentheses. All
listed elements must be legal lvalues. Only alphanumeric
identifiers may be lexically scoped--magical built-ins
like $/ must currently be "local"ize with "local" instead.

Unlike dynamic variables created by the "local" operator,
lexical variables declared with "my" are totally hidden
from the outside world, including any called subroutines.
This is true if it's the same subroutine called from
itself or elsewhere--every call gets its own copy.

This doesn't mean that a "my" variable declared in a stat-
ically enclosing lexical scope would be invisible. Only
dynamic scopes are cut off. For example, the "bumpx()"
function below has access to the lexical $x variable
because both the "my" and the "sub" occurred at the same
scope, presumably file scope.

vilfred ☆☆ ()
Ответ на: Re: PERL и use strict от golodranez

Re: PERL и use strict

> так когда я use Strict отключаю, все работает

так оно для этого и служит. привносит в всеобщее языковое
безобразие Perl ограничения C. многие рекомендуют писать
только в strict режиме...

signal11 ()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.