|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
I want to jump over a part or parts of the program on a condition. i have seen reference to a 'goto' function, but its use is discouraged and there is no discussion of how to use it. basically i have several hundred conditionals. right now i run through them all, but i want to be able to skip whole sets of them if a certain condition is met, or if another condition is not met.
so if want to test if ( $debt_ratio_back > 50) then --goto somewhere-- else keep going if ( ( $aa{LoanTransaction} =~ /Purchase/ | | $aa{LoanTransaction} =~ /RTRefinance/) && $aa{IncomeDocs} =~ /FullDoc/ # && $aa{Employment} =~ /SE/ && ( $aa{PropertyType} =~ /SFD/ | | $aa{PropertyType} =~ /TH/ | | $aa{PropertyType} =~ /Condo/ | | $aa{PropertyType} =~ /2U/ | | $aa{PropertyType} =~ /MH/) && $aa{PropertyOccupancy} =~ /PR/ && $aa{CreditScore} >= 681 && $aa{M30Lates} == 0 && $aa{M60Lates} == 0 && $aa{M90Lates} == 0 && $aa{M30Last24No} =~ /No/ && $aa{BK} >= 4 && $aa{CH13Open} =~ /No/ && $aa{CollLast2} =~ /No/ # && $aa{CondProp} =~ /ave/ && $debt_ratio_front <= 35 && $debt_ratio_back <= 45 && $aa{CreditLines24} >= 5 && $aa{RI30LessMore2} <= 2 && $aa{I30Last12} <= 0 && $aa{I60Last12} == 0 && $aa{I90Last12} == 0 && $aa{R30Last12} <= 0 && $aa{R60Last12} == 0 && $aa{R90Last12} == 0 ) somewhere i would have a bunch of this type of thing. I see warnings regarding spaghetti code. what are my options. thanks for any help |
|
#2
|
|||
|
|||
|
Yeah, back before they had functions and OO programming, they used goto all the time and you would end up jumping all over your program based on conditions. This was not only mind bogoling to keep track of, but it also created lots of spageti code.
You want to do it in a sub routine, like this (simple example): ---------------- $variable='fdstesttest'; $do=&check_content($variable); if(defined(&$do)){&$do}else{die "No $do subroutine"} sub check_content { my $check=shift; if($check=~/blah/){return 'blah'} if($check=~/test/){return 'asdf'} return 'nothin'; } sub blah { print "BLAH!"; } sub asdf { print "asdf!"; } sub nothin { print "I didn't find anything!"; } ------- Now this is a bit of a roundabout way of doing it, but just know that 'return' exits a subroutine.. and if a value is specified, it will return that value. In this case, it would run the asdf subroutine (because it would match 'test' from the variable). |
|
#3
|
||||
|
||||
|
[QUOTE]Originally posted by ohopp:
I want to jump over a part or parts of the program on a condition. i have seen reference to a 'goto' function, but its use is discouraged and there is no discussion of how to use it.[QUOTE] You can test for failure like this: for (keys %aa) { $err = 1, last if /^LoanTransaction$/ and $aa{$_} !~ /^(Purchase|RTRefinance)$/; ... etc. } if ($err) ... Or you can use constraint subs: for (keys %aa) { $err = 1, last unless loan_tr(); $err = 1, last unless ... } sub loan_tr { return ($_[0] =~ /^(Purchase|RTRefinance)$/); } |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > 'goto' on condition - or the best way to get there |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|