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);

Recommended Answers

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 …

Jump to Post

All 4 Replies

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.

Sorry, I meant my @left = Exception::excep(\@array,\@toexcept,$number,$n); not Exception->excep After fixing the above errors your script will still fail with at least one other runtime error. I haven't found all of them. Have a look at http://perldoc.perl.org/perlfaq3.html#How-do-I-debug-my-Perl-programs? for tips on debugging Perl scripts.

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...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.