in reply to Number of times I've used goto in Perl
The point is that if goto were avoided using ifs, there would be one nesting level per error condition. Using &&= enables the code to cascade (without extra nested blocks) to the end whenever an error occurs. But many might consider the &&= too techy for the average programmer. Any thoughts, alternatives?sub fred { # meeting all three requirements:- my ($t, $u, $v, $w, $x, $y) = @_; somelogger( 5, "fred", "start of fred"); my $ok = method1($t); $ok &&= method2($u); my $pid = open my $ph, "/somewhere/program $v |"; my $output = ''; $ok &&= method3( <$ph>, \$output ); close $ph; waitpid $ph,0; # and so on for functionality using $w, $x and $y (in worst case s +cenario) # if goto were used to jump to the exit point the # label would have been here. if ($ok) { somelogger( 5, "fred", "fred completed successfully"); } else { somelogger( 5, "fred", "error during fred"); } return $ok; }
One world, one people
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Number of times I've used goto in Perl
by jdporter (Paladin) on Mar 26, 2015 at 20:19 UTC | |
Re^2: Number of times I've used goto in Perl
by ikegami (Patriarch) on May 06, 2018 at 08:10 UTC | |
Re^2: Number of times I've used goto in Perl
by AnomalousMonk (Archbishop) on Mar 25, 2015 at 22:03 UTC | |
Re^2: Number of times I've used goto in Perl (sub, return++)
by tye (Sage) on Mar 26, 2015 at 00:03 UTC | |
by AnomalousMonk (Archbishop) on Mar 26, 2015 at 01:02 UTC | |
by tye (Sage) on Mar 26, 2015 at 01:32 UTC | |
by shagbark (Acolyte) on May 06, 2018 at 02:36 UTC |