Is it possible to use a single line foreach loop in Perl?
$hash{$thing}++ foreach my $thing (@things);
I know this is possible with many other commands such as,
die "Invalid file!\n" if (open($Handle, "file.txt"));
I know that open statement maybe broken 🙂
Almost. In the foreach suffix, you must use $_:
Or equivalently (since
forandforeachare aliased for syntax):