Skip to content

Instantly share code, notes, and snippets.

@mephinet
Created June 7, 2018 11:02
Show Gist options
  • Save mephinet/cae22f1061e662879fb9c8511de901e9 to your computer and use it in GitHub Desktop.
Save mephinet/cae22f1061e662879fb9c8511de901e9 to your computer and use it in GitHub Desktop.
#! /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