Created
June 7, 2018 11:02
-
-
Save mephinet/cae22f1061e662879fb9c8511de901e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env perl | |
use strict; | |
use warnings; | |
my $s = "foo\nbar\n"; | |
open my $fh, '<', \$s; | |
# this while is OK, because it's top-level | |
while (<$fh>) { } | |
sub fn_good { | |
# this while is OK too, because it localizes | |
local $_ = undef; | |
while (<$fh>) { } | |
return; | |
} | |
sub fn_good_too { | |
# this while is OK too, because it binds | |
while ( my $x = <$fh> ) { } | |
return; | |
} | |
sub fn_bad { | |
# this while is bad, because it modifies the outer topic | |
while (<$fh>) { } | |
return; | |
} | |
my @data = ( 42, 43 ); | |
fn_bad() for @data; | |
die "My data is gone!\n" unless $data[0]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment