perl学习之argument
Arguments are the values you pass to a Perl script. Each value on the command line after the name of the script will be assigned to the special variables$ARGV[0],$ARGV[1],$ARGV[2], and so on. The number of arguments passed to the script is stored in the$#ARGVvariable, and the full argument string is in the variable@ARGV. The name of the currently running program is stored in the$0variable.
Let's try some examples working with arguments and other special variables. Create an executable script calledtestvars.plcontaining these lines:
#!/usr/bin/perl
print "My name is $0 \n";
print "First arg is: $ARGV[0] \n";
print "Second arg is: $ARGV[1] \n";
print "Third arg is: $ARGV[2] \n";
$num = $#ARGV + 1; print "How many args? $num \n";
print "The full argument string was: @ARGV \n";
Now if you run this script, here's what you'll see:
$./testvars.pl dogs can whistle
My name is testvars.pl
First arg is: dogs
Second arg is: can
Third arg is: whistle
How many args? 3
The full argument string was: dogs can whistle
Just a few notes about that example. I did say that the$#ARGVvariable contained the number of arguments, but I lied--sort of. Since the arguments are numbered starting at zero, you have to add one to the value of$#ARGVto get the actual number of arguments. It's a bit weird, but if you're a fan of the C language, it'll all seem quite normal.
Also note that the@ARGVvariable doesn't start with a dollar sign. That's because it's anarrayvariable, as opposed to the regularscalarvariables we've worked with so far. An array can be thought of as a list of values, where each value is addressed by a scalar (dollar sign) variable and an index number in square brackets, as in$ARGV[0],$ARGV[1], and so on. Don't worry too much about arrays for now--that's a topic for more study on your own.
perl学习之argument的更多相关文章
- perl学习笔记---标量
1.perl 输出时,使用 逗号,连接多个字符串 如:print “The answer is ”,6*7, “.\n” 2.当一个字符串由双引号括起来时,如果变量前没有反斜线,则变量会被其值内插 $ ...
- perl学习之路1
一切要从Hollo world开始 公司要用perl....啊, 不会只能自学了, 毕竟是公司啊, 不是学校...公司不学习就滚蛋了...惨惨惨 因为是学习嘛, 感觉开虚拟机比较麻烦所以直接用了个 瘟 ...
- Perl 学习笔记-高级控制结构
1.unless控制结构 类似于独立的else语句; 要么条件为真, 要么执行语句块内的代码; unless(<condition>){code...;} 等价于 if(<con ...
- Perl 学习笔记-标量数据
最近学习Perl, 准备看一遍入门指南,关键的东西还是记录下来,以便以后复习和查看参考. 笔记来自<<Perl语言入门第5版>> 1. 在Perl内部,不区分整数值和浮点数值, ...
- perl学习笔记一
标量数据 标量:数字.字符.可以存储在标量变量中也可以从文件和设备中读取. 数字:所有数字内部格式相同——双精度浮点数. 浮点数直接量:程序员在程序中直接键入的数字. 整数直接量:6129804028 ...
- perl学习之:use and require
本文和大家重点学习一下Perl use和require用法对比,这两个函数都是一个意思,加载和引用Perl的模块,或者是子程序,区别在于Perl use是在当前默认的里面去寻找,一旦模块不在指定的区域 ...
- perl学习之路3
Perl编程之路3 标签: perl 列表与数组 Perl里面代表复数的就是列表和数组 列表(list)指的是标量的有序集合, 而数组(array)则是存储列表的变量. 在Perl这两个属于尝尝混 ...
- perl学习之路2
这些主要是从 "小骆驼" 书上粘贴或者摘抄出来的, 个人认为需要记的语法知识 "在某些情况下, 你可能需要在一台机器上写程序, 再传送到另一台机器上运行.这时候, 请使用 ...
- perl学习笔记
一.正则表达式 匹配一个文件中的某个单词,并打印出来 #!/usr/bin/perl use strict; use warnings; ; open(FILE, "< temp.pl ...
随机推荐
- Turtles (非纯分块)
http://codeforces.com/contest/103/problem/D #include <bits/stdc++.h> using namespace std; type ...
- Python/WSGI 应用快速入门--转
http://uwsgi-docs-cn.readthedocs.io/zh_CN/latest/WSGIquickstart.html 这个快速入门指南将会向你展示如何部署简单的 WSGI 应用和普 ...
- 在WIN7、WIN8中,将快捷方式锁定到任务栏,C#
其实很简单,使用 API 函数 ShellExecute,就可以解决这个问题. 首先添加引用 using System.Runtime.InteropServices; 代码如下: using Sys ...
- MyBatis框架的XML数据访问Dao层接口的组合使用
MyBatis 的前生为Apache的开源项目iBatis.其优势在于灵活,几乎可以替代JDBC,同时提供了编程接口.目前MyBatis的数据访问Dao层不需要实现类,也不需要像JDBC那样拼接Hql ...
- 【原创】微信公众号与HTML 5混合模式揭秘4——jssdk调用微信扫一扫
微信公众号与HTML 5混合模式揭秘1——如何部署JSSDK 微信公众号与HTML 5混合模式揭秘2——分享手机相册中照片 微信公众号与HTML 5混合模式揭秘3——JSSDK获取地理位置 在JS ...
- VC运行时库(/MD、/MT等)
VC项目属性→配置属性→C/C++→代码生成→运行时库 可以采用的方式有:多线程(/MT).多线程调试(/MTd).多线程DLL(/MD).多线程调试DLL(/MDd).单线程(/ML).单线程调试( ...
- jquery mobile 的手指上下滑动文章、导航栏
导航栏的js设置 <!--导航栏的滚动 --> <script type="text/javascript"> var myScroll, pullDown ...
- 超简单!一步创建自己的wifi热点~
还在用某某卫士.某某管家创建wifi热点,甚至被忽悠专门买一个随身wifi吗?现在答案明确了:你完全用不着它们了.因为有更简单的方法. 只需要两个bat文件.一个用来启动wifi热点,另一个用来关闭w ...
- windows Git的安装和使用
一.本人是根据廖雪峰大神的个人官网学习的git,并有感而发以做笔记的方式写下这篇博客,希望可以帮助到自己和其他人,廖雪峰个人官网http://www.liaoxuefeng.com/ 二.声明我的电脑 ...
- MySQL分表操作的例子
USE project;DROP PROCEDURE IF EXISTS project.delete_test_user;delimiter $$CREATE PROCEDURE project.d ...