I really new in Perl. I tried to create a simple script to
find the duplicate items in array. Here is my source code:
###########################################################
@arry = ("1", "2", "2", "2", "3", "3");
@dups = ();
@copiedArry = @arry;
$size = @arry;
$arryLoc = $size - 1;
for ($i=0; $i<=$arryLoc; $i++)
{
for ($j=0; $j<=$arryLoc; $j++)
{
while ($size != 0)
{
if($copiedArry[$i] eq $arry[$j]) # <==
{
push(@dups, $arry[$j]);
delete $arry[$j];
$size --;
}
else
{
$size --;
}
}
}
}
print "Here are the dups: \n";
foreach $data (@dups)
{
print $data ."\n";
}
##########################################################
see line with #<==, I got "Use of uninitialized value in string eq at
C:\Perl Projects\testing.pl line 17."
Is the way I created correct? Why I got "uninitialized value..." like that?
Thanks,
Lucas
find the duplicate items in array. Here is my source code:
###########################################################
@arry = ("1", "2", "2", "2", "3", "3");
@dups = ();
@copiedArry = @arry;
$size = @arry;
$arryLoc = $size - 1;
for ($i=0; $i<=$arryLoc; $i++)
{
for ($j=0; $j<=$arryLoc; $j++)
{
while ($size != 0)
{
if($copiedArry[$i] eq $arry[$j]) # <==
{
push(@dups, $arry[$j]);
delete $arry[$j];
$size --;
}
else
{
$size --;
}
}
}
}
print "Here are the dups: \n";
foreach $data (@dups)
{
print $data ."\n";
}
##########################################################
see line with #<==, I got "Use of uninitialized value in string eq at
C:\Perl Projects\testing.pl line 17."
Is the way I created correct? Why I got "uninitialized value..." like that?
Thanks,
Lucas