Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: An exploration of higher-level-language approaches to the "First all-zero row in an NxN matrix" problem (goto Considered Harmful)

by BrowserUk (Pope)
on Sep 24, 2011 at 21:37 UTC ( #927685=note: print w/ replies, xml ) Need Help??


in reply to An exploration of higher-level-language approaches to the "First all-zero row in an NxN matrix" problem (goto Considered Harmful)

One regret I have with several of these examples is that by wrapping them in functions I had to change "last" to "return" several times.

You seem to see the use of return as a poor substitute for last, but to my way of thinking, it is the correct solution. This because it should work in any language that supports subroutines including those in use back when this debate was first started, in a clear and direct way free of flags and gotos and short-circuiting at every opportunity:

#! perl -slw use strict; sub checkRow { my $ref = shift; $_ and return 1 for @$ref; return; } sub firstAllZeroRow { my $ref = shift; checkRow( $ref->[ $_ ] ) // return $_ for 0 .. $#$ref; return; } my @array = ( [ qw/ 1 1 1 1 1 / ], [ qw/ 0 1 1 0 0 / ], [ qw/ 0 0 0 0 1 / ], [ qw/ 0 0 0 0 0 / ], [ qw/ 0 1 0 1 0 / ], ); print firstAllZeroRow( \@array ); __END__ C:\test>junk50 3

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re: An exploration of higher-level-language approaches to the "First all-zero row in an NxN matrix" problem (goto Considered Harmful)
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://927685]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2014-12-26 20:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls