PERLTRAP(1) | Perl Programmers Reference Guide | PERLTRAP(1) |
use English;
allows you to refer to special variables (like $/) with names (like $RS), as though they were in awk; see perlvar for details.
Awk Perl ARGC scalar @ARGV (compare with $#ARGV) ARGV[0] $0 FILENAME $ARGV FNR $. - something FS (whatever you like) NF $#Fld, or some such NR $. OFMT $# OFS $, ORS $\ RLENGTH length($&) RS $/ RSTART length($`) SUBSEP $;
for my $variable (keys %hash) { ... }
Furthermore, don't forget the "keys" in there, as "foreach my $kv (%hash) {}" iterates over the keys and values, and is generally not useful ($kv would be a key, then a value, and so on).
condition ? do_something() : variable = 3
and the variable is only assigned if the condition is false. In Perl, you need parentheses:
$condition ? do_something() : ($variable = 3);
Or just use "if".
Note also that the variable is not visible until the following statement. This means that in "my $x = 1 + $x" the second $x refers to one declared previously.
for ($object) { $_->method; }
while (<FH>) { } while (defined($_ = <FH>)) { }.. <FH>; # data discarded!
$x = /foo/; $x =~ /foo/;
As always, if any of these are ever officially declared as bugs, they'll be fixed and removed.
2019-10-21 | perl v5.30.3 |