View Single Post
  #4  
Old 03-13-2008, 03:14 PM
Kagehi
Sarnak
 
Join Date: Feb 2008
Location: Arizona, USA
Posts: 33
Default

Ok. This **seems** to work, after a lot of hair pulling and confusion as to what the frack was going on. Obviously, it should be tested more rigorously than I have. lol

Code:
sub check_handin {
  my $hashref = shift;
  my $copy_hash = $hashref;
  my %required = @_;
  foreach my $req (keys %required) {
        do {
	  if (defined $hashref->{$req}) {
	    if ($hashref->{$req} <= $required{$req}) {
	      $required{$req} = $required{$req} - $hashref->{$req};
              delete $hashref->{$req};
	      if ($required{$req} == 0) {delete $required{$req};}
	    }
	    elsif ($hashref->{$req} > $required{$req}){
                $hashref->{$req} = $hashref->{$req} - $required{$req};
	        delete $required{$req};
	    } else {
	      $hashref = $copy_hash;
              return(0);
	    }
	  }
	  else {
	    $hashref = $copy_hash;
	    return(0);
	  }
	} until !defined $required{$req};
  }
Again, if the server where set up with a configuration option is turn off stacks, then this will pass, but the turn in won't work. What happens in that case... Another test might need to be added to this, to make sure that stacks are turned on, before even bothering to do any more checking.

Time to go bounce around the rubber room a bit, and recover from trying to figure this code out in a language that looks, to me, like someone threw cartoon curse words at the screen. !%$%@!^%& = "open a gate to the Pegasus Galaxy", right? lol
Reply With Quote