Help me to find where I am wrong

package Exception;
sub excep{
     my ($ref_numbers,$ref_exceptions,$number,$n) = @_;
	 my @excepts;
	 if ($number == 0)
	 {
	   return (\@excepts);
	   }
	   else{
	 my $i;
	 for($i=0;$i<$n;$i++)
	 {
	  my $a=0;
	  if($i != $$ref_execptions[$number])
	  {
	     $excepts[$a] = $i;
		 $a++;
		} else {
		        $a++;
				}
			
		}
		$number--;
		
		&excep(\@excepts,$ref_exceptions,$number,$n);
		}
				
	 
	 }
use Exception;
my @array = (1,5,6,9,2);
my @toexcept = (5,6);
my $number = 2;
my $n = 5;
my @left = &excep(\@array,\@toexcept,$number,$n);

Comparing this line my ($ref_numbers,$ref_exceptions,$number,$n) = @_; with if($i != $$ref_execptions[$number]) It looks like a typo in $$ref_execptions.

The last statement in the Exception module should return a value of 1 because the use command requires a value of 1 to indicate the successful loading of the module. my @left = &excep(\@array,\@toexcept,$number,$n); The above tries to call a subroutine in the main package rather than Exception. You need either to specify Exception->excep or import the excep method into your main package.

Edited 5 Years Ago by d5e5: n/a

I am very confused with variables you used in the subroutine arguments! You keep changing it around and there is no comment at all... At least comment each input argument and gives an expected output.

If you are stuck, write a pseudo code first. It looks like your algorithm is not completely correct...

Edited 5 Years Ago by Taywin: n/a

This article has been dead for over six months. Start a new discussion instead.