Home >php教程 >PHP开发 >5 common mistakes in Perl

5 common mistakes in Perl

黄舟
黄舟Original
2016-12-16 13:47:141275browse

I am using perl+mdbm+sPRead to make things recently.

php has been used for a long time. I have used python and ruby. I have never touched the classic scripting language perl. Now I am reading the textbook like a primary school student.

I found that perl is indeed much more difficult. Nothing else makes me make mistakes so often.

1. The first common mistake is: outputting content to a file. The standard syntax is:

print STDERR "this is an apple.";

I usually write it as

print STDERR, "this is an apple.";

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

2. The second common mistake is: often missing the arrow referenced by Hash.

should be written as

print $hash->{$key};

I often write as

print $hash{$key};

3. The third common mistake 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") {
                                                                                                                                             }

This will lead to logical errors that are difficult to detect.见4. The fourth common error:

IF statement without parentheses (all pHP is bad)


The correct way is:

IF ($ var) {

Print "yes";

}

I often write

if($var)

print "yes";

5. There is another mistake, which is not brought from php, and most people probably won't make it: missing a semicolon.

The above is the content of 5 common errors in Perl. For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:python pickle moduleNext article:python pickle module