in reply to (jeffa) Re: permutation understanding
in thread permutation understanding

if ($food) { print "$food\n"; eat (substr($food,0,length($food)-1)); }

Yes recursion can be instructive, but be careful not to mismatch a conditional test with the logical intent of the test. Your test of true or false doesn't mesh with your logical intent of recursing based on the length of the string. Try eating the string "012345" and your recursion ends too early because a string can have a non-zero length and still be false.

Replies are listed 'Best First'.
Re: Re: (jeffa) Re: permutation understanding
by greywolf (Priest) on May 25, 2002 at 18:36 UTC
    A simple fix:
    if (exists $food) { }
    Update: Oops, I jumped the gun on that one.

    mr greywolf
      which version of Perl are you using??? exists may be used on hash or array elements or subroutines, not scalar variables.

      Er, what he means is, you want to test for definedness....

      ..Jon

      Update - you're right Anonymous. Mea culpa. My embarrassed apologies to all. )c:

        Testing with defined would be "infinitely" worse than either the simple true/false test which has a potential off-by-one error or the broken usage of exists. Please test your suggested "fixes".