Five common errors in Perl


I’ve been using Perl + mdbm + spread recently.

PHP has been used for a long time. Python and Ruby have been used together. Perl, the classic scripting language, has never been touched. Now it’s nibbling at textbooks like a primary school student.

It’s really much more difficult to find Perl. Other things didn’t make me make mistakes so often.

1. The first common error is to output content to a file. The standard syntax is:

print STDERR “this is an apple.”;

I usually write

print STDERR,”this is an apple.”;

Always type a comma more. To be honest, I seldom make mistakes repeatedly, but I just can’t remember this place.

2. The second common error is that the arrows referenced by hash are often omitted.

It should have been written

print $hash->{$key};

I often write

print $hash{$key};

3. The third common error is string comparison:

PHP has been used for a long time, always using two equal signs to compare strings. This is wrong. The correct way of writing is

if($var eq “hello”) {
print “world”;

I often write:

if($var==”hello”) {
print “world”;

This can lead to logic errors that are hard to detect.

4. The fourth common error:

If statements without parentheses (all bad in PHP)

The correct way of writing is:

print “yes”;

I often write

print “yes”;

5. There is another error, which is not brought from PHP. It is not expected to be made by ordinary people: missing semicolon.

Recommended Today

Deeply analyze the principle and practice of RSA key

1、 Preface After experiencing many dark moments in life, when you read this article, you will regret and even be angry: why didn’t you write this article earlier?! Your darkest moments include: 1. Your project needs to be connected with the bank, and the other party needs you to provide an encryption certificate. You have […]