B
blaine
Hey,
I have this ugly code below that I would like to get rid of everything
in the switch statement. My preference would be to have something
simple that just takes and id and calls that sub routine number.
I suppose I could use and eval like
eval( "\$self->DisplayPage$subpage_id");
but was wondering if someone can think of something better, as then if
there is an error it's trapped in eval..
Code I'd like to clean is below...
SWITCH: for ($subpage_id)
{
if (/^1$/) {$self->DisplayPage; last SWITCH;}
elsif (/^2$/) {$self->DisplayPage2; last SWITCH;}
elsif (/^3$/) {$self->DisplayPage3; last SWITCH;}
elsif (/^4$/) {$self->DisplayPage4; last SWITCH;}
elsif (/^5$/) {$self->DisplayPage5; last SWITCH;}
elsif (/^6$/) {$self->DisplayPage6; last SWITCH;}
elsif (/^7$/) {$self->DisplayPage7; last SWITCH;}
elsif (/^8$/) {$self->DisplayPage8; last SWITCH;}
elsif (/^9$/) {$self->DisplayPage9; last SWITCH;}
}
Thanks,
Blaine
I have this ugly code below that I would like to get rid of everything
in the switch statement. My preference would be to have something
simple that just takes and id and calls that sub routine number.
I suppose I could use and eval like
eval( "\$self->DisplayPage$subpage_id");
but was wondering if someone can think of something better, as then if
there is an error it's trapped in eval..
Code I'd like to clean is below...
SWITCH: for ($subpage_id)
{
if (/^1$/) {$self->DisplayPage; last SWITCH;}
elsif (/^2$/) {$self->DisplayPage2; last SWITCH;}
elsif (/^3$/) {$self->DisplayPage3; last SWITCH;}
elsif (/^4$/) {$self->DisplayPage4; last SWITCH;}
elsif (/^5$/) {$self->DisplayPage5; last SWITCH;}
elsif (/^6$/) {$self->DisplayPage6; last SWITCH;}
elsif (/^7$/) {$self->DisplayPage7; last SWITCH;}
elsif (/^8$/) {$self->DisplayPage8; last SWITCH;}
elsif (/^9$/) {$self->DisplayPage9; last SWITCH;}
}
Thanks,
Blaine