for (my $i = 0; $i <= $#foo; $i++) { # BAD foreach (@foo) { # BETTER
for (my $i = <STDIN>; $i; $i = <STDIN>) { # BAD while (my $i = <STDIN>) { # BETTER
my $array = [ 'one', 'two', 'three' ];
my $hash = { one => 1, two => 2, three => 3 };
There is no other way to specify a regular expression match like this in Perl outside of a match or substitution operation.
m//
), Regex substitute (s///
), and translate (tr///
, y///
) work the same wayqq// qq#A decent <html> delimiter </html> # qq( man perl(1) for details ) # valid!
use vars
.my
local
is not what you think, use my
instead unless you know why you're using localour
only when your package needs a global variableSubmit a PR to github.com/petdance/perl101
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.