Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old December 8th, 2000, 01:08 AM
ohopp ohopp is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: Frederick, Md, US
Posts: 0 ohopp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old December 8th, 2000, 04:01 PM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 9
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).

Reply With Quote
  #3  
Old December 8th, 2000, 10:00 PM
vpopper's Avatar
vpopper vpopper is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: Southern California
Posts: 73 vpopper User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 24 sec
Reputation Power: 9
[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)$/); }



Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > 'goto' on condition - or the best way to get there


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway