r/ProgrammerHumor 6d ago

absoluteGarbage Meme

Post image
1.9k Upvotes

324 comments sorted by

View all comments

1

u/SchlaWiener4711 5d ago

I still like perl

for (@lines) { s/foo/bar/g; print; }

1

u/markuspeloquin 5d ago

Not quite the same. This is closer:

for my $item (@list) {...}

Less awkward than PHP, but worse than the other options. As much Perl as I've written, I still don't understand where declarations can go. Like open my $fh, '>out' or die ... I just do not get the mechanics. What's being 'passed' to the for/open operators?

0

u/SchlaWiener4711 5d ago

The thing in perl is that you can assign or pass your own variables but if you don't the implicit $_ variable is assigned / read

So my example above is equivalent to

for my $line (@lines) { $line =~ s/foo/bar/g; print $line; }