1. Use anti-quotation marks to call an external program and return the output of the program, such as $cwd = ' pwd ';
2. The difference between the variable types in Perl is mainly singular and plural; Singular variables are called scalar $scalar, and complex variables are called array @array. In Perl There are also Hash, Handle, Typeglob, and reference variable types. Scalars in Perl can use = assignment, which can point to references to complex data structures, such as other variables or objects.
References in 3.Perl
$ary= \@myarray;#referencing a named array$hsh= \%myhash;#referencing a named hash$sub= \&mysub;#referencing a named subroutine$ary= [1,2,3,4,5];#referencing an anonymous array$hsh= {"Roger"="A","R"=4};#referencing anonymous hashes$sub=Sub{Print "hello\n";}#referencing an anonymous subroutine$fido= new Camel"Amelia";#referencing an object
4. Complex variables in Perl
= = needs to provide a list environment to the right of the assignment equation, using an array when a number lookup is needed, and hashing if you need to find it by name
= = can be used to simply implement two scalar value exchanges by the list assignment: ($var 1,$var 2) = ($var 2,$var 1);
= = Because the hash is a special array, you can get a single hash element through {}, such as: $roger {' name '}, note that because it is a scalar, it is preceded by $, not%, which represents the entire hash table. If you use%roger{' name '}, you get the key value Together. In addition, the string to the left of the fat arrows does not need to be quoted (auto Plus), but not on the right (considering supporting complex data structures), so it is not possible to conflict with reserved words.
The value of the hash can be separated by commas, so it may be used for automatic construction, such as:
$longday = {"Sun","Sunday","Mon ","Monday"};
5. Complex data structures in Perl
In Perl, commas are used to delimit, parentheses are used for grouping, but not a list can be converted to scalar; If you need to convert a list to a scalar to use [], the expression is an anonymous array; If you want to convert a hash to a scalar, you need to use {} to indicate that it is an anonymous hash. So you can define a hash
$wife{"Jacob"}=["A","B","C","D"];#print "$wife {\" jacob\ "}[0]\n";Print $wife{"Jacob"}[0]."\ n";## A$kids _of_wife{"Jacob"} = { "A"= ["A1","A2"],"B"= ["B1","B2"],"C"= ["C1","C2"],"D"= ["D1","D2"] };#print "$kids _of_wife{\" jacob\ "}{\" a\ "}[0]\n";Print $kids _of_wife{"Jacob"}{"A"}[0]."\ n";## A1
6. The loop variable in the Foreach loop in Perl directly refers to the array element itself, modifying the loop variable to modify the original array, and unlike Java, you can modify the original array in foreach.
7. Using line input and $_ can be a simple program and add extensibility, such as matching a link in a file:
while (<FILE>) { printif /http:/; Print if /ftp:/; Print if /mailto:/; ... }
Perl language Programming >> Learning notes