From: Philip Rhoades Date: 2012-11-22T01:31:02+09:00 Subject: Re: Alternatives to methods for large number of nested "ifs" - SOLVED On 2012-11-18 00:50, Philip Rhoades wrote: > People, > > Thanks to the people who responded - I looked at everything but > nothing really suited what I was trying to do but see below for some > progress that I made and another question: > > > On 2012-11-17 01:35, Philip Rhoades wrote: >> People, >> >> I have an existing script that looks like: >> >> lots of code >> . >> . >> . >> if .. >> some lines of code >> if .. >> some lines of code >> if .. >> some lines of code >> if .. >> some lines of code >> if .. >> some lines of code >> etc >> >> This makes it difficult to see the overall logic so I want to change >> it to something like: >> >> lots of code >> . >> . >> . >> if .. >> call something >> if .. >> call something >> if .. >> call something >> if .. >> call something >> if .. >> call something >> etc >> >> but if I use methods I will have to pass lots of variables or use >> global variables and then it gets clumsy changing everything - is >> there some way of simply calling a block of code and then returning >> to >> the same position in the nested "ifs"? > > > I found that I could use sequential "ifs" instead of nested "ifs" by > using "exit" statements in each "if" block - the script is processing > incoming mails and can exit when a mail has been satisfactorily > classified. I still have something like this: > > > lots of code > if block - small > lots of code > if block - small > if block - large > if block - small > if block - large > . > . > etc > > > What I want is to be able to see the whole logic of the program in > about 25 lines (ie one screenfull of code - ie all the "if" > statements) - I could probably use standard methods for the > repetitive > small "if" blocks but for the large "lots of code" and "if block - > large" I definitely can't. Is it possible that a method can be > forced > to NOT use local variables? - then I could replace the large blocks > with these sorts of methods. procs were the solution (they allow shared variables) - I now have this at the end of the program: #### Mailing-List:, Delivered-To: and Reply-To: lines p_mailing_list.call #### OK line_To non-blocked domains p_line_To_non_blocked_domains.call #### OK in_mailing_list p_in_mailing_list.call #### Drop in_black_list_to p_in_black_list_to.call #### Drop in_black_list_from AND !Srejector content p_in_black_list_from.call #### Drop Bounce Bounced - deleting old quarantined file if it exists p_bounce_bounced.call #### Reject LinkedIn invitation p_LinkedIn.call #### OK Srejector content - incoming/outgoing p_Srejector.call #### OK in_domains_list - for incoming/outgoing mails, system mails etc p_in_domains_list.call #### OK put me on your whitelist subject p_put_me_on_your_whitelist_subject.call #### OK To: line p_line_To.call #### Drop !in_white_list_to p_not_in_white_list_to.call #### Drop !in_white_list_to_substr p_not_in_white_list_to_substr.call #### OK in_white_list_from p_in_white_list_from.call #### Drop in_subject_list p_in_subject_list.call #### Reject !in_white_list_from p_not_in_white_list_from.call #### OK shouldn\'t get here? p_shouldnt_get_here.call Regards, Phil. -- Philip Rhoades GPO Box 3411 Sydney NSW 2001 Australia E-mail: phil@pricom.com.au