<2>集腋成裘
标量项: [root@wx03 2]# cat a1.pl
unshift(@INC,"/root/big/2");
use Horse;;
print $Horse::days;
print "\n";
[root@wx03 2]# cat Horse.pm
package Horse;
our $days="test111";
1; $Horse::days; 访问Horse 包中的变量$days 有时候你想为"所有名叫foo的东西"(无论他的印记是什么)起一个名字 。为此, 符号团记录可以有一个*作为前缀,这里的星号(*)表示所有其 他的印记。 这些称为类型团(typeglobs) perl main包: [root@wx03 2]# cat a2.pl
$bert="aa";
print "\$bert is $bert\n";
print "\$::bert is $::bert\n";
print $main::bert;
print "\n";
[root@wx03 2]# perl a2.pl
$bert is aa
$::bert is aa
aa 2.6.3 选择自己的引号: ` ` qx// 执行命令 是 [root@wx03 2]# cat a4.pl
@arr=`ls -ltr`;
print @arr;
print "\n"; @arr=qx/ls -ltr/;
print @arr;
print "\n"; [root@wx03 2]# cat a5.pl
print __LINE__;
print "\n";
print __FILE__;
print "\n";
print __LINE__;
print "\n";
[root@wx03 2]# perl a5.pl
1
a5.pl
5 __LINE__ 当前行号 __FILE__ 当前文件 [root@wx03 2]# cat a6.pl
print __PACKAGE__;
print "\n";
[root@wx03 2]# perl a6.pl
main 当前包为main包 [root@wx03 2]# cat a7.pl
print "111111111\n";
print "222222222\n";
print __END__;
print "333333333\n";
[root@wx03 2]# perl a7.pl
111111111
222222222
[root@wx03 2]# END 可以用于真正的文件结束符之前表示搅拌的逻辑结束, 任何后面的文本都被忽略 [root@wx03 2]# cat a8.pl
sub funkshun{
return(a1,a2,a3)}; $x=funkshun(); print "\$x is $x\n"; @x=funkshun();
print "\@x is @x\n"; [root@wx03 2]# perl a8.pl
$x is a3
@x is a1 a2 a3 2.7.3 空(void )环境: [root@wx03 2]# cat a9.pl
$stuff = ( "one", "two", "three");
print "\$stuff is $stuff\n";
[root@wx03 2]# perl a9.pl
$stuff is three 只是把值"three" 赋予了变量$stuff [root@wx03 2]# cat a10.pl
@stuff = ("one", "two", "three");
print "\@stuff is @stuff\n"; $stuff = @stuff;
print "\$stuff is $stuff\n";
[root@wx03 2]# perl a10.pl
@stuff is one two three
$stuff is 3 [root@wx03 2]# cat a11.pl
@stuff=(1,2,3);
@nonsense=(4,5,6);
sub funkshun{
return 100; }; @arr=(@stuff,@nonsense,funkshun());
print @arr;
print "\n";
print $arr[6];
print "\n";
[root@wx03 2]# perl a11.pl
123456100
100 [root@wx03 2]# cat a12.pl
%map = (
red => 0xff0000,
green => 0x00ff00,
blue => 0x0000ff,
); print $map{red};
print "\n";
[root@wx03 2]# perl a12.pl
16711680 初始化任何当作记录使用的匿名散列引用: [root@wx03 2]# cat t1.pl
$rec = {
NAME => 'John Simth',
RANK => 'Captain',
SERNO => '951413',
}; print $rec->{NAME};
print "\n";
[root@wx03 2]# perl t1.pl
John Simth 或者用命名的参数激活复杂的函数: 2.10 型团(typeglob) Perl 里面有种特殊的类型叫类型团(typeglob)用以保留整个符号表 记录。(符号表记录
*foo 包括 $foo, @foo, %foo,&foo 和其他几个 foo 的简单解释 值。)类型团
(typeglob)的类型前缀上一个 *,因为它代表所有类型。 [root@wx03 2]# cat t3.pl
$fh=*var;
$var=aa;
print "\$fh is $fh\n"; print "\$fh is $$fh\n"; [root@wx03 2]# perl t3.pl
$fh is *main::var
$fh is aa [root@wx03 2]# cat t3.pl
$fh=*var;
$var=aa;
print "\$fh is $fh\n"; print "\$fh is $$fh\n"; $bar="bbb";
*foo = \$bar;
print "\$foo is $foo\n"; $a1="aaaa111";
*foo=\$a1;
print $foo;
print "\n";
[root@wx03 2]# perl t3.pl
$fh is *main::var
$fh is aa
$foo is bbb
aaaa111 符号表就是引用: [root@wx03 2]# cat t4.pl
$bar="abc123";
*foo=\$bar;
print *foo;
print "\n"; print $foo;
print "\n";
[root@wx03 2]# perl t4.pl
*main::foo
abc123 2.11.2 行输入(尖角)操作符
[root@wx03 2]# cat t5.pl
while ($_ = <STDIN>) { print $_; };
[root@wx03 2]# perl t5.pl
1
1
33
33
<2>集腋成裘的更多相关文章
- 集腋成裘-13-git使用-02进阶篇
上一篇我们简单介绍了如何安装和使用git,本次将简单介绍如何创建分支.处理冲突.提交与回滚 创建和合并分支是Git的一大特色. 使用场景:当有一个新功能要开发,但是又没有确定上线时间,不能合并到主干上 ...
- 集腋成裘-12-git使用-01创建库
一.git安装教程 git安装比较简单,选择好安装路径,直接默认下一步即可 1:检查git是否安装成功 二.SourceTree工具 1:下载&安装 安装过程中如何免注册? 在C:\Users ...
- 集腋成裘-11-sql性能优化
SQL Nexus是一个用于将SQL Trace数据.性能监视日志及T-SQL输出整合进一个单独的SQL Server数据库的工具. 先决条件 开始使用SQL Nexus之前,注意下面要做的事项: 安 ...
- 集腋成裘-09-ECharts -HelloECharts-02
上一篇我们讲了可视化数据分析的重要性以及ECharts的一些的特性,这一篇我们继续学习一下ECharts的简单Demo 一:5 分钟上手 ECharts <!DOCTYPE html> & ...
- 集腋成裘-08-ECharts -简介-01
目标:让数据说话. 大数据时代的到来以及有效应用,大幅度提升了企业的管理能力.决策科学化与可执行性水平,推动传统决策方式朝着数据驱动转型.可视化数据分析对决策者产生的意义将在事前预测.事中感知以及事后 ...
- 集腋成裘-06-angularJS -angular_02
1.0 选项卡 其中涉及到了三目运算符号; <!DOCTYPE html> <html ng-app="test"> <head> <me ...
- 集腋成裘-05-angularJS -初识angular
私以为angular的最大特点是:只关注数据 1.1 angular之:双向绑定 <!DOCTYPE html> <html ng-app=""> < ...
- 集腋成裘-03-css基础-02
1.1 三种写法 内嵌式:样式只作用于当前文件,没有真正实现结构表现分离 外链式:作用范围是当前站点,真正实现了内容与表现分离 行内样式:仅限于当前标签,结构混在一起 1.2 标签分类 1.2.1 块 ...
- 集腋成裘-02-css基础-01
CSS 层叠样式表(Cascading Style Sheets)(级联样式表) 1 选择器 1.1 写法 选择器是一个选择标签的过程. 选择器{属性:值;...} 1.2 基础选择器 标签选择器 类 ...
随机推荐
- Fundamental types
Fundamental types void type boolean type character types integer types Modifiers signedness size Pro ...
- 我的Python成长之路---GitHub使用之注册GitHub并安装Git客户端
一.注册GitHub账号 进入GitHub官方网站,输入用户名.邮箱地址及密码,点击“Sign up for GitHub”. 选择免费的,不要问我为什么,除非有钱任性选择付费版 验证邮箱地址并激活G ...
- Ubuntu上搭建DokuWiki
1.准备工作 1) 安装Apache sudo apt-get install apache2 2)在浏览器中输入http://localhost 如果现实It works则说明Apache安装成功, ...
- 生成pdf文件
- zk create() 方法
create() $path = $zkh->create($req_path, $data); $path = $zkh->create($req_path, $data, 'flags ...
- Linux fstab 参数详解
[root@qs-wg-db1 /]# cat /etc/fstab LABEL=/ / ext3 defaults ...
- maven常见问题汇总
package阶段得到的是build目录下编译后的类包(jar),install是把这个包和一些maven的元信息(比如pom.xml)复制到本地仓库,assembly一般是把build结果和一些资源 ...
- [置顶] 正则表达式应用:匹配email地址
email的组成主要有三部分 1用户名部分 2@ 3域名部分 1用户名部分 用户名一般有数值字母下划线组成,所以正则表达式为:[\da- ...
- 疯狂JAVA讲义第三章之数组篇
package test; /** * Desription: * @author orangebook *<br/>网站:<a href="http://www.cr ...
- ESRI Shapefiles (SHP)
ESRI Shapefiles (SHP) Also known as ESRI ArcView Shapefiles or ESRI Shapefiles. ESRI is the company ...