SoFunction
Updated on 2025-04-07

5 common errors in perl

I've been using perl+mdbm+spread to make things recently.

PHP has been used for a long time, and has used python and ruby. I haven't touched the classic scripting language before. Now I'm chewing textbooks like a primary school student.

I found that perl is indeed much more difficult. Other things didn't make me mistakes so often.

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

print STDERR "this is an apple.";

I usually write it

print STDERR,"this is an apple.";

Always make an extra comma. To be honest, I rarely make mistakes repeatedly, but I just can't remember this place.

2. The second common error is: the arrows referenced by Hash are often missed.

It should have been written

print $hash->{$key};

I often write

print $hash{$key};

3. The third common error is: string comparison:

After using php for a long time, I always use two equal signs to compare strings. This is wrong. The correct way to write it is

if($var eq "hello") {
print "world";
}

I often write:

if($var=="hello") {
print "world";
}

This will lead to logical errors and it is difficult to check.

4. The fourth common error:

If statements do not have brackets (all are bad in PHP)

The correct way to write it is:

if($var)
{
print "yes";
}

I often write

if($var)
print "yes";

5. There is another mistake that was not brought from PHP. Most people probably won’t make it: missed semicolons.