加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Learning Perl: 5.3. The Invocation Arguments

发布时间:2020-12-15 20:56:27 所属栏目:大数据 来源:网络整理
导读:? 5.3. The Invocation Arguments Technically,the diamond operator isn't looking at the invocation argumentsit works from the @ARGV array. This array is a special array preset by the Perl interpreter as the list of the invocation arguments.

Previous Page

Next Page

?

5.3. The Invocation Arguments

Technically,the diamond operator isn't looking at the invocation argumentsit works from the @ARGV array. This array is a special array preset by the Perl interpreter as the list of the invocation arguments. In other words,this is like any other array,(except for its funny,all caps name),but when your program starts,@ARGV is already stuffed full of the list of invocation arguments.[

]

[

] C programmers may be wondering about argc(there isn't one in Perl),and what happened to the program's own name (that's found in Perl's special variable $0,not @ARGV). Depending upon how you've invoked your program,there may be a little more happening than we say here. See the perlrun manpage for the full details.

You can use @ARGV like any other array; you can shift items off of it or use foreach to iterate over it. You could even check to see if any arguments start with a hyphen,so you could process them as invocation options (like Perl does with its own -w option).[Dagger;]

[Dagger;] If you need more than one or two such options,you should almost certainly use a module to process them in a standard way. See the documentation for the Getopt::Long and Getopt::Std modules,which are part of the standard distribution.

The diamond operator looks in @ARGV to determine what filenames it should use. If it finds an empty list,it uses the standard input stream; otherwise,it uses the list of files that it finds. This means that after your program starts and before you start using the diamond,you've got a chance to tinker with @ARGV. For example,here we can process three specific files regardless of what the user chose on the command line:

    @ARGV = qw# larry moe curly #;  # force these three files to be read
    while (<>) {
      chomp;
      print "It was $_ that I saw in some stooge-like file!/n";
    }

Previous Page

Next Page

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读