Method One: In the shell using export to output a variable, and in Perl using the special variable%env to get shell ' s variables.
i.e.:
---shell box---
$/bin/ksh
# Export X=foo
# perl-e ' Print $ENV {' x '} '
-------------
Method Two: Perl, like C, also has array @argv that store command-line arguments, which can be used to handle individual command-line arguments; unlike C, $ARGV [0] is the first argument, not the program name itself.
$var = $ARGV [0]; # first parameter
$numargs = @ARGV; # Number of parameters
The,<> operator in Perl is actually an implied reference to an array of @argv, which works as follows:
1. When the Perl interpreter first sees <>, open the file with $argv[0] as filename;
2, carry out action shift (@ARGV); That is, the elements that @argv the array are moved forward one, and the number of elements is reduced by one.
3. The <> operator reads all the rows in the file opened in the first step.
4, after reading, the interpreter returned to the first step repeat.
Cases:
@ARGV = ("Myfile1", "myfile2"); #Actually assigned by command line arguments
while ($line = <>) {
Print ($line);
}
The contents of the file Myfile1 and Myfile2 will be printed out.