Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Perl: When DWIM Doesn't. Parent comment
I would write your code as:
foo($_) foreach @bar; sub foo { my $var = shift; $var =~ s/foo/bar/; print $var; }
foo foreach @bar; sub foo { my $var = $_; $var =~ s/foo/bar/; print $var; }
foo foreach @bar; sub foo { my $_ = $_; s/foo/bar/; print; }
There are no comments on this comment yet.
I would write your code as:
You can also fix this is to localize $_ inside the function, if you don't want to pass $_ as a parameter. You can even use $_ instead of $var (although it looks a little weird assigning $_ to itself):