in reply to Recursive If statement not working.

Look at your if statement  if(( lc($autoSubmit) ne "y") and ($autoSubmit ne "n"))--

if $autoSubmit='Y'", the first clause of the AND statement is 'true' and the second clause is 'false'. The result of 'true' AND 'false' is 'false' and the control bypasses the if-block. Same argument applies for 'N' as well. Use OR logic for this.

or use

return(lc $autoSubmit) if (lc $autoSubmit eq 'y'); return(lc $autoSubmit) if (lc $autoSubmit eq 'n'); autoSubmit();
Note: You can also us a while loop and get rid of the "subroutine" call.

----
I Go Back to Sleep, Now.

OGB

Replies are listed 'Best First'.
Re^2: Recursive If statement not working.
by Transient (Hermit) on Jun 25, 2009 at 19:49 UTC
    Actually, the way that it is is correct, albeit it should be if ( (lc($autosubmit) ne "y") and (lc($autosubmit) ne "n") )

    Truth tables:
    p q ~p ~q p^q ~p v ~q ~( p ^ q ) T T F F T F F T F F T T F F F T T F T F F F F T T F T T
    where p = lc($autosubmit) eq "y" and q = lc($autosubmit) eq "n" if $autosubmit is "Y", then p is True and q is false (lc("Y") = "y" but lc("Y") does not equal "n"), thus the statement as a whole is false and we do not enter the loop. The only time the loop is activated is if both conditions fail ( that is $autosubmit is neither "y" nor "n" ). Conversely (or contrapositively, whatever the term is - I forget), the same could be written as:
    unless ( lc($autosubmit) eq "y" or lc($autosubmit) eq "n" )
    shown above as ~(p ^ q)

    Update: wow, I need to re-read - you come to the same conclusions, but it's just that the OP wants to bypass the "if" in that case (either y or n). So I posted truth tables in vain =) The issue here is that it will only be called once - on the first failure.