Here we will summarize the issues that need to be paid attention to when programming in the Perl language.
1. the hash value is not sequential, so the values returned by the hash function are all sort, rather than the status when the hash value is assigned. For example:
my %hash2=( ‘ten‘ => 10, ‘fiirt‘ => 1, ‘second‘ => 2, ‘third‘ => 3, ‘fouth‘ => 4);print keys %hash2;---result-----fiirtsecondthirdfouthten
Using the hash function each, the result is also obtained through sort, for example:
my %hash2=( ‘ten‘ => 10, ‘fiirt‘ => 1, ‘second‘ => 2, ‘third‘ => 3, ‘fouth‘ => 4);while (my ($key, $value) = each %hash2) { print "$key => $value\n";}-----result------fiirt => 1second => 2third => 3fouth => 4ten => 10
2. There is no difference between Perl variables, array variables, and hash variables and UNDEF. If my (strict requirement) is not used, it cannot be used. The value is UNDEF only if it is defined but not assigned a value. For example, an error occurs in the following example.
if (%dfd) { print ‘ok‘;} else { print ‘not ok‘;}
3. When an undefined value is used as a number, Perl automatically converts it to 0. If you use warnings; use strict. Although the program reports an error, it still produces results.
print 12*$a;------result-------Name "main::a" used only once: possible typo at ts2.pl line 19.Use of uninitialized value $a in multiplication (*) at ts2.pl line 19.0[nan@localhost pl]$ fg
4. <> when reading a file, the UNDEF value is returned after the last row is read, in order to end the loop. For example:
open FILE, "<tt.pl" or die "the file tt.pl can not be opened $!";while(<FILE>) { print;}
However, when <stdin> reads data from the keyboard, if a while loop is used, it cannot jump out of the loop, so it is best to set a special character to jump out of the loop. For example:
while (<>) { last if (/^EOF$/); print;}
Perl: Notes for Perl programming.