变量“显式包名称”问题
好的,我知道这对于来自其他语言的人来说似乎是一个常见问题 - 在我的例子中是 C/C++ 和 PHP。 然而,经过研究、检查和反复检查后,我的挫败感战胜了我。
我正在使用 -
use strict;
use warnings;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
这是出现错误的子函数 -
#
# function MergePolygonCircle
#
# parameters
# Polygon - 2 dimensional array reference
# Circle - 2 dimensional array reference
# CircleCenter - array
# Radius - circle radius float
#
# returns - nuthin
#
sub MergePolygonCircle
{
my ($Polygon, $Circle, $CircleCenter, $Radius) = @_;
my $BuffIndex = 0;
my $SegIndex = 0;
my $FirstBuffIndex = -1;
my $FirstCircIndex = -1;
my $EndBuffIndex = -1;
my $EndCircIndex = -1;
my $PolygonLength = @$Polygon; # de-referencing the polygon array to get its size
my $CircleLength = @$Circle;
# check to see if the center point of the circle is inside the polygon
if(GetDistance(@$Polygon[0][0], @$Polygon[0][1], @$CircleCenter[0], @$Ci rcleCenter[1]) <= $Radius)
{
# at this point, the opposite side can only be outside of this circle
my $Offset = ceil($PolygonLength / 2)-1;
# remove the end point
my $EndPoint = pop(@$Polygon);
# extract the section before the offset
my $Points = splice(@$Polygon, 0, $Offset);
# put the points back at the beginning
splice(@$Polygon, $PolygonLength - $Offset - 1, 0, @$Points);
# reapply the end point
push(@$Polygon, @$Polygon[0]);
}
# Find the start and end intersections
for($BuffIndex = 0; $BuffIndex < $PolygonLength-1; $BuffIndex++)
{
for($SegIndex = 0; $SegIndex < $CircleLength-1; $SegIndex++)
{
if(SegmentsIntersect(@$Polygon[$BuffIndex][0], @$Po lygon[$BuffIndex][1], @$Polygon[$BuffIndex+1][0], @$Polygon[$BuffIndex+1][1],
@$Circle[$SegIndex][0], @$Circle[$SegIndex][1], @$Circle[$SegIndex+1][0], @$Circle[$SegIndex+1][1]))
{
if($FirstBuffIndex == -1)
{
$FirstBuffIndex = $BuffIndex;
$FirstCircIndex = $SegIndex;
continue;
}
else
{
if($SegIndex != $FirstCircIndex)
{
$EndBuffIndex = $BuffIndex;
$EndCircIndex = $SegIndex;
}
}
}
if($FirstBuffIndex > -1 && $EndBuffIndex > -1) break;
}
if($FirstBuffIndex > -1 && $EndBuffIndex > -1) break;
}
if($FirstBuffIndex > -1 && $EndBuffIndex > -1 && $FirstCircIndex > -1 && $End CircIndex > -1)
{
$FirstBuffIndex++;
$EndBuffIndex++;
$FirstCircIndex++;
if($FirstCircIndex < $EndCircIndex) $EndCircIndex++;
# remove redundant segments in the main buffer
splice(@$Polygon, $FirstBuffIndex, ($EndBuffIndex - $FirstBuffIndex));
# insert the new segments
if($FirstCircIndex < $EndCircIndex)
{
# remove the tail
$Tail = splice(@$Polygon, $FirstBuffIndex);
# re-join here
push(@$Polygon,
splice(@$PolyCircle, $FirstCircIndex, $EndCircIndex - $FirstCircIndex)),
@$Tail);
}
if($EndCircIndex < $FirstCircIndex)
{
# remove the tail
$Tail = splice(@$Polygon, $FirstBuffIndex);
$CircTop = splice(@$PolyCircle, $FirstCircIndex);
$CircTail = splice(@$PolyCircle, 0, $EndCircIndex);
# stitch them all together
push(@$Polygon, @$CircTop, @$CircTail, @$Tail);
}
}
};
我收到诸如此类的错误 -
"my" variable $PolygonLength masks earlier declaration in same scope
Global symbol "$BuffIndex" requires explicit package name
Global symbol "$PolygonLength" requires explicit package name
Global symbol "$SegIndex" requires explicit package name
Global symbol "$CircleLength" requires explicit package name
Global symbol "$Polygon" requires explicit package name
我看不到这些错误来自何处。我意识到这有点长,但在我的上一个问题中,我被要求提供“真实”代码...
更新
抱歉,我忘记提及我正在通过 CGI 使用版本 5.12.3(Windows 下的 apache)
Ok, I know that this would appear to be a common problem for people coming from other languages - in my case C/C++ and PHP.
However, after having researched and checked and double checked, my frustration has got the better of me.
I am using -
use strict;
use warnings;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
Here is the sub function where the errors arrise -
#
# function MergePolygonCircle
#
# parameters
# Polygon - 2 dimensional array reference
# Circle - 2 dimensional array reference
# CircleCenter - array
# Radius - circle radius float
#
# returns - nuthin
#
sub MergePolygonCircle
{
my ($Polygon, $Circle, $CircleCenter, $Radius) = @_;
my $BuffIndex = 0;
my $SegIndex = 0;
my $FirstBuffIndex = -1;
my $FirstCircIndex = -1;
my $EndBuffIndex = -1;
my $EndCircIndex = -1;
my $PolygonLength = @$Polygon; # de-referencing the polygon array to get its size
my $CircleLength = @$Circle;
# check to see if the center point of the circle is inside the polygon
if(GetDistance(@$Polygon[0][0], @$Polygon[0][1], @$CircleCenter[0], @$Ci rcleCenter[1]) <= $Radius)
{
# at this point, the opposite side can only be outside of this circle
my $Offset = ceil($PolygonLength / 2)-1;
# remove the end point
my $EndPoint = pop(@$Polygon);
# extract the section before the offset
my $Points = splice(@$Polygon, 0, $Offset);
# put the points back at the beginning
splice(@$Polygon, $PolygonLength - $Offset - 1, 0, @$Points);
# reapply the end point
push(@$Polygon, @$Polygon[0]);
}
# Find the start and end intersections
for($BuffIndex = 0; $BuffIndex < $PolygonLength-1; $BuffIndex++)
{
for($SegIndex = 0; $SegIndex < $CircleLength-1; $SegIndex++)
{
if(SegmentsIntersect(@$Polygon[$BuffIndex][0], @$Po lygon[$BuffIndex][1], @$Polygon[$BuffIndex+1][0], @$Polygon[$BuffIndex+1][1],
@$Circle[$SegIndex][0], @$Circle[$SegIndex][1], @$Circle[$SegIndex+1][0], @$Circle[$SegIndex+1][1]))
{
if($FirstBuffIndex == -1)
{
$FirstBuffIndex = $BuffIndex;
$FirstCircIndex = $SegIndex;
continue;
}
else
{
if($SegIndex != $FirstCircIndex)
{
$EndBuffIndex = $BuffIndex;
$EndCircIndex = $SegIndex;
}
}
}
if($FirstBuffIndex > -1 && $EndBuffIndex > -1) break;
}
if($FirstBuffIndex > -1 && $EndBuffIndex > -1) break;
}
if($FirstBuffIndex > -1 && $EndBuffIndex > -1 && $FirstCircIndex > -1 && $End CircIndex > -1)
{
$FirstBuffIndex++;
$EndBuffIndex++;
$FirstCircIndex++;
if($FirstCircIndex < $EndCircIndex) $EndCircIndex++;
# remove redundant segments in the main buffer
splice(@$Polygon, $FirstBuffIndex, ($EndBuffIndex - $FirstBuffIndex));
# insert the new segments
if($FirstCircIndex < $EndCircIndex)
{
# remove the tail
$Tail = splice(@$Polygon, $FirstBuffIndex);
# re-join here
push(@$Polygon,
splice(@$PolyCircle, $FirstCircIndex, $EndCircIndex - $FirstCircIndex)),
@$Tail);
}
if($EndCircIndex < $FirstCircIndex)
{
# remove the tail
$Tail = splice(@$Polygon, $FirstBuffIndex);
$CircTop = splice(@$PolyCircle, $FirstCircIndex);
$CircTail = splice(@$PolyCircle, 0, $EndCircIndex);
# stitch them all together
push(@$Polygon, @$CircTop, @$CircTail, @$Tail);
}
}
};
I am getting errors such as -
"my" variable $PolygonLength masks earlier declaration in same scope
Global symbol "$BuffIndex" requires explicit package name
Global symbol "$PolygonLength" requires explicit package name
Global symbol "$SegIndex" requires explicit package name
Global symbol "$CircleLength" requires explicit package name
Global symbol "$Polygon" requires explicit package name
I cannot see where these errors are coming from. I realise that this is a bit long, but in my last question I was asked for "real" code ...
Update
Sorry, I forgot to mention that I am using version 5.12.3 through CGI (apache under windows)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此行有语法错误:
如果
$Polygon
是对二维数组的引用,则应使用$Polygon->[0][0]
或${$Polygon}[0][0]
。请参阅 perldoc perlref。This line has syntax errors:
If
$Polygon
is a reference to a two-dimensional array you should use$Polygon->[0][0]
or${$Polygon}[0][0]
. See perldoc perlref.看来您编写了太多的 C 代码:-)
Perl 中的 if 语句需要一个块。
C 中的“break”在 Perl 中拼写为“last”。
另外,
这不会起作用,你可能想要
It appears that you write too much C code :-)
if statements in Perl require a block.
"break" in C is spelled "last" in Perl.
Also,
isn't going to work, you probably want