亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: ARGV、$ARGV、$ARG、@ARGV四者的關(guān)系及區(qū)別??? [打印本頁]

作者: gaoquanlong    時間: 2008-09-18 16:21
標(biāo)題: ARGV、$ARGV、$ARG、@ARGV四者的關(guān)系及區(qū)別???
請幫忙解釋一下它們之間的關(guān)系及區(qū)別,謝謝!
@ARGV是傳遞的腳本的命令行參數(shù)。

[ 本帖最后由 gaoquanlong 于 2008-9-18 17:21 編輯 ]
作者: forlorngenius    時間: 2008-09-18 17:34

作者: xiaoshengcaicai    時間: 2008-09-18 17:42
哦。。。搞不懂。。查查。。

[ 本帖最后由 xiaoshengcaicai 于 2008-9-18 18:36 編輯 ]
作者: gaoquanlong    時間: 2008-09-18 17:51
ARGV [ALL] 特殊的文件句柄,它遍歷在 @ARGV 里的所有命令行文件名。通常寫成尖角操作符 里的空文件句柄:<>。

$ARGV [ALL] 當(dāng)使用 <> 或者 readline 操作符從 ARGV 句柄里讀取數(shù)據(jù)的時候,包含當(dāng)前 文件名。

Perl語言學(xué)習(xí)(第三版中文版):第二十八章:特殊名字,里邊的內(nèi)容。
我就是不理解這些關(guān)系,所以才問的。。。。。。
作者: xiaoshengcaicai    時間: 2008-09-18 18:33
好拗口啊。。。

ARGV

    [ALL] The special filehandle that iterates over command-line filenames in @ARGV. Usually written as the null filehandle in the angle operator: <>.
$ARGV

    [ALL] Contains the name of the current file when reading from the ARGV handle using the <> or readline operators.
@ARGV

    [ALL] The array containing the command-line arguments intended for the script. Note that $#ARGV is generally the number of arguments minus one, since $ARGV[0] is the first argument, not the command name; use scalar @ARGV for the number of program arguments. See $0 for the program name.


$ARGV跟ARGV都是跟<>鉆石操作符有關(guān)系的

@ARGV保存了命令行的所有參數(shù)


比如 test.pl  1.txt 2.txt

@ARGV  為(1.txt, 2.txt)

程序里如果寫
while (<>) {
      print "from file $ARGV  get line:" , $_, "\n";
}

將依次讀入1.txt, 2.txt, 并依次讀入每一行。 $ARGV表示當(dāng)前正在讀取的文件名, ARGV表示當(dāng)前正在讀取的文件句柄。

[ 本帖最后由 xiaoshengcaicai 于 2008-9-18 18:46 編輯 ]
作者: xiaomm250    時間: 2014-04-23 14:12
xiaoshengcaicai 發(fā)表于 2008-09-18 18:33
好拗口啊。。。

回答的非常不錯,解決了我的疑問
作者: jason680    時間: 2014-04-23 14:49
回復(fù) 1# gaoquanlong

Here is the document

$ perldoc perlvar
NAME
    perlvar - Perl predefined variables
    ...

SPECIAL VARIABLES
    The following names have special meaning to Perl. Most punctuation names
    have reasonable mnemonics, or analogs in the shells. Nevertheless, if you
    wish to use long variable names, you need only say:

            use English;
   
    ...
   
  General Variables
    $ARG
    $_      The default input and pattern-searching space. The following pairs
            are equivalent:
            ...

    @ARG
    @_      Within a subroutine the array @_ contains the parameters passed to
            that subroutine. Inside a subroutine, @_ is the default array for
            the array operators "push", "pop", "shift", and "unshift".
            
            See perlsub.
            ...

    It's easy to notice the problem in such a short example, but in more
    complicated code you are looking for trouble if you don't localize changes
    to the special variables.

    $ARGV   Contains the name of the current file when reading from "<>".

    @ARGV   The array @ARGV contains the command-line arguments intended for
            the script. $#ARGV is generally the number of arguments minus one,
            because $ARGV[0] is the first argument, ESC[4mnotESC[0m the program'
s command
            name itself. See $0 for the command name.

    ARGV    The special filehandle that iterates over command-line filenames
            in @ARGV. Usually written as the null filehandle in the angle
            operator "<>". Note that currently "ARGV" only has its magical
            effect within the "<>" operator; elsewhere it is just a plain
            filehandle corresponding to the last file opened by "<>". In
            particular, passing "\*ARGV" as a parameter to a function that
            expects a filehandle may not cause your function to automatically
            read the contents of all the files in @ARGV.







歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2