Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Loop controls transcends scope?

by TGI (Parson)
on Jan 15, 2009 at 21:39 UTC ( #736682=note: print w/replies, xml ) Need Help??

in reply to Loop controls transcends scope?

If you decide Corion's excellent advice and enable warnings for your code while body of the code intact, you can suppress this warning easily.

sub test { my ( $s ) = @_; if ($s == 3) { no warnings 'exiting'; # suppress the warning for this lexical +scope only. next; } else { print $s . "\n"; } }

My personal preference is to use something more like this:

use strict; use warnings; my @stuff = 1..5; for my $s (@stuff) { next if is_bad_stuff($s); my $formatted = format_stuff($s); print "$formatted: passed\n"; } sub is_bad_stuff { my ( $s ) = @_; return $s == 3; } sub format_stuff { my ( $s ) = @_; $s = '<UNDEF>' return "Formatted $s"; }

The downside of this is the extra function call. The upside is that it's (hopefully) easier to read and maintain.

I like to collect code with side-effects (like printing) into as few places as possible, so my format_stuff routine preps the data for output but does not emit it. I know this is a toy example, but the habit has served me well.

TGI says moo

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://736682]
LanX Much enemy much ore
[Corion]: marto: Naah, my module doesn't care, but the users of my module might expect some things to work in Chrome that only work in later builds (or, as seems to be the case, don't work there either ;) )
[Corion]: But I really wonder - I can tell Chrome to go offline, but requesting pages over the network still succeeds. But if I manually click the "offline" checkbox, that's different :-/

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2017-12-12 20:26 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (336 votes). Check out past polls.