Home: Perl Programming Help: Intermediate:
Am I being a dumb ass ?



Nosfer
Novice

May 8, 2002, 12:44 AM


Views: 1693
Am I being a dumb ass ?

Yeah, great question I might say. Look at the structure I have right about now :


Code
if ( $dag_stat eq ".." && $dag_stataf eq "Z" ) { $melding = "vm werk en nm ziek "; } 
if ( $dag_stat eq ".." && $dag_stataf eq "M" ) { $melding = "vm werk en nm missie "; }
if ( $dag_stat eq ".." && $dag_stataf eq "V" ) { $melding = "vm werk en nm verlof "; }
if ( $dag_stat eq ".." && $dag_stataf eq "A" ) { $melding = "vm werk en nm afwezig "; }
if ( $dag_stat eq ".." && $dag_stataf eq "R" ) { $melding = "vm werk en nm recuup "; }
if ( $dag_stat eq ".." && $dag_stataf eq "S" ) { $melding = "vm werk en nm speciaal verlof "; }
if ( $dag_stat eq ".." && $dag_stataf eq "P" ) { $melding = "vm werk en nm part time "; }
if ( $dag_stat eq ".." && $dag_stataf eq "C" ) { $melding = "vm werk en nm compensatie "; }
if ( $dag_stat eq ".." && $dag_stataf eq "N" ) { $melding = "vm werk en nm ploegen "; }

if ( $dag_stat eq "ZZ" && $dag_stataf eq "Z" ) { $melding = "heel de dag ziek "; }
if ( $dag_stat eq ".Z" && $dag_stataf eq "." ) { $melding = "vm ziek en nm werk "; }
if ( $dag_stat eq ".Z" && $dag_stataf eq "M" ) { $melding = "vm ziek en nm missie "; }
if ( $dag_stat eq ".Z" && $dag_stataf eq "V" ) { $melding = "vm ziek en nm verlof "; }
if ( $dag_stat eq ".Z" && $dag_stataf eq "A" ) { $melding = "vm ziek en nm afwezig ZC "; }
if ( $dag_stat eq ".Z" && $dag_stataf eq "R" ) { $melding = "vm ziek en nm recuup "; }
if ( $dag_stat eq ".Z" && $dag_stataf eq "S" ) { $melding = "vm ziek en nm speciaal verlof "; }
if ( $dag_stat eq ".Z" && $dag_stataf eq "P" ) { $melding = "vm ziek en nm part time "; }
if ( $dag_stat eq ".Z" && $dag_stataf eq "C" ) { $melding = "vm ziek en nm compensatie "; }
if ( $dag_stat eq ".Z" && $dag_stataf eq "N" ) { $melding = "vm ziek en nm ploegen "; }


Lots of lots of lots of if's (the real list is about 6 times bigger, and for 5 days ... so 30 times bigger.

Is there a way to do it better ?

Is there a variable that can say "ok found it now get the hell out of here " like "break;" en Java ?

CheerZ!!! Smile


Kanji
User

May 8, 2002, 10:56 AM


Views: 1687
Re: [Nosfer] Am I being a dumb ass ?

A common way of implementing this is by using hashes...


Code
my %dag_stat = ( 
".." => {
"Z" => "vm werk en nm ziek ",
"M" => "vm werk en nm missie ",
},
"ZZ" => {
"Z" => "heel de dag ziek ",
},
".Z" => {
"." => "vm ziek en nm werk ",
"M" => "vm ziek en nm missie ",
"V" => "vm ziek en nm verlof ",
},
);

$melding = $dag_stat{$dat_stat}->{$dag_stataf};


And then if you find that a lot of keys share the same values, you could further extend the $melding assignment to check for defaults.


Code
my %dag_stat = ( 
"default" => {
"Z" => "vm werk en nm ziek ",
"M" => "vm werk en nm missie ",
},
".." => {
"Z" => "vm werk en nm ziek (Z)",
},
);

$melding = $dag_stat{$dat_stat}->{$dag_stataf}
|| $dag_stat{'default'}->{$dag_stataf}
|| "";

--k.