Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
The problem currently is like this, there is lot of different functions that wants different data and along the way they call other functions and so on. and i really need a fast way to tell when even one of them fails without changing too much code. as im trying find a solution that does not make things even more complicated than they already are, but still doing it most effective and reasonable way possible.
So after many hours of pondering, i can't really think a better way of doing this than those lovely goto labels everyone loves so much.
Here is a demonstration of the current solution.
#!/usr/bin/perl use strict; use warnings; my (%Numbers,$i); my @Values = qw/first second third/; $Numbers{$_} = ++$i for @Values; for my $cur (@Values) { my $value = &get_number ($cur); $value .= &get_ordinal ($cur); # more, more.. print "$cur is $value\n"; next; FAILED: print "WRONG: $cur, because: $@!\n"; next; } sub get_number { my $value = shift; if ($value eq "second") { &error("bad value"); } return $Numbers{$value}; } sub get_ordinal { return substr(shift, -2); } sub error { $@ = shift; goto FAILED; }
Just thought to ask if anyone ever dash against this kind of problem and found more elegant solution than the following. And yes i would rewrite it if it was up to me.
-Tauno, Thank you for your time.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Jumping trought lot of subroutines
by GrandFather (Saint) on Jul 04, 2006 at 00:42 UTC | |
|
Re: Jumping trought lot of subroutines
by imp (Priest) on Jul 04, 2006 at 07:17 UTC | |
|
Re: Jumping trought lot of subroutines
by shmem (Chancellor) on Jul 04, 2006 at 10:46 UTC |