引用本身就是一种标量变量

引用变量,如 $ra 或$rarray ,就是一种普通的标量变量,因为我们使用"$" 符号。

变量变量可以是一个整数,一个字符串或者一个引用,而且还可以被重新任意的赋值为这些数据类型中的任一种

Vsftp:/root/perl/10# cat a1.pl
my $arr="111"; my $ref=\$arr; print $ref;
print "\n";
Vsftp:/root/perl/10# perl a1.pl
SCALAR(0xa50e38) 间接访问: 间接访问的意思就是取得引用所指的变量的值 Vsftp:/root/perl/10# cat a2.pl
use Data::Dumper;
my $var="aa";
my $key=\$var;
$hash{$key}=11;
print Dumper(%hash);
print "\n"; Vsftp:/root/perl/10# perl a2.pl
$VAR1 = 'SCALAR(0x1f19438)';
$VAR2 = 11; 对标量变量的引用 对数组的引用: Vsftp:/root/perl/10# cat a5.pl
my @array=qw/ ab bc cd de ef/;
print "\$array[2] is $array[2]\n"; Vsftp:/root/perl/10# perl a5.pl
$array[2] is cd Vsftp:/root/perl/10# cat a5.pl
my @array=qw/ ab bc cd de ef/;
print "\$array[2] is $array[2]\n"; print "\@array is @array\n"; my @arr2=@array[0,1,3];
print "\@arr2 is @arr2\n"; Vsftp:/root/perl/10# perl a5.pl
$array[2] is cd
@array is ab bc cd de ef
@arr2 is ab bc de 简明的箭头记号: Perl 提供了另一种简单易读的用以存取数组和散列表元素的语法结构:"->[]" 记号 Vsftp:/root/perl/10# cat a6.pl
my @array=qw/ab bc cd de ef/;
$rarray=\@array;
print $rarray;
print "\n";
print @$rarray;
print "\n";
print "11111111\n";
print $$rarray[1];
print "\n";
print "2222222222\n";
print $rarray->[1];
print "\n"; Vsftp:/root/perl/10# perl a6.pl
ARRAY(0xf82450)
abbccddeef
11111111
bc
2222222222
bc 与数组类似, 你可以通过使用->{} 记号来存取散列表中的数据元素: Vsftp:/root/perl/10# cat a7.pl
%hash=("a"=>"b","c1"=>"d2","dd"=>"eq21");
print %hash;
print "\n"; $rhash=\%hash;
print $$rhash{"dd"};
print "\n";
print $rhash->{"dd"};
print "\n"; Vsftp:/root/perl/10# perl a7.pl
abddeq21c1d2
eq21
eq21 不存在自动间接访问: Vsftp:/root/perl/10# cat a8.pl
$rarray=\@array;
push ($rarray ,1,2,3); Vsftp:/root/perl/10# perl a8.pl
Type of arg 1 to push must be array (not scalar dereference) at a8.pl line 2, near "3)"
Execution of a8.pl aborted due to compilation errors. push 第一个参数必须是数组 Vsftp:/root/perl/10# cat a8.pl
$rarray=\@array;
push (@$rarray ,1,2,3);
print $rarray;
print "\n";
print @$rarray;
print "\n"; Vsftp:/root/perl/10# perl a8.pl
ARRAY(0x211f480)
123 使用引用: Vsftp:/root/perl/10# cat a9.pl
@array1=(1,2,3);
@array2=(4,5,6,7);
AddArrays (\@array1,\@array2);## 以引用方式传递数组 print "\@array1 is @array1\n";
print "\@array2 is @array2\n"; sub AddArrays
{
my ($rarray1,$rarray2) = @_;
$len2 = @$rarray2; ##array2的长度
print "\$len2 is $len2\n";
for ($i = 0;$i<$len2;$i++){
print "\$i is $i\n";
my $str = $rarray1->[$i] + $rarray2->[$i];
print "\$str is $str\n";
}
};
Vsftp:/root/perl/10# perl a9.pl
$len2 is 4
$i is 0
$str is 5
$i is 1
$str is 7
$i is 2
$str is 9
$i is 3
$str is 7
@array1 is 1 2 3
@array2 is 4 5 6 7 运行效率: 通过使用引用,我们可以高效的向子例程中传入或传出大量数据 匿名存储的引用: 到目前为止,我们学习创建了对已存在变量的引用,现在我们要学习对"匿名"数据结构的引用, 也就是那些没有同变量名关联的值 创建匿名数组,需要使用方括号而不是圆括号,如: $ra = []; ##创建一个空的匿名数组,并返回对它的引用 $ra = [1,"hello"];## 创建一个经过 Vsftp:/root/perl/10# cat a10.pl
my $rh=(1,"hello");
print "\$rh is $rh\n";
Vsftp:/root/perl/10# perl a10.pl
$rh is hello ## 这是一个普通的使用%前缀的散列表,它由圆括号所包围的列表初始化 Vsftp:/root/perl/10# cat a11.pl
%hash = ("flock"=>"birds","pride" =>"lions");
print %hash;
print "\n";
Vsftp:/root/perl/10# perl a11.pl
flockbirdspridelions ##匿名散列表是一组用大括号括起来的列表 Vsftp:/root/perl/10# perl a12.pl
$a is
$$a is hello world 多重引用的间接访问: Vsftp:/root/perl/10# cat a13.pl
$rarray=[a1,b2,c3,d4,e5];
print $rarray->[1];
print "\n";
print $$rarray[1];
print "\n"; Vsftp:/root/perl/10# perl a13.pl
b2
b2 嵌套数据结构: 20Vsftp:/root/perl/10# cat a14.pl
%sue = (
'name' => 'Sue',
'age' => '45'); %john = (
'name' =>'John',
'age' =>'20'); %peggy = (
'name' => 'Peggy',
'age' =>'16'); @children = (\%john,\%peggy);
$sue{'child'} = \@children; print $sue{'child'}->[0]->{age};
Vsftp:/root/perl/10# perl a14.pl
20Vsftp:/root/perl/10# 隐含的创建复杂的数据结构: Vsftp:/root/perl/10# cat a14.pl
%sue = (
'name' => 'Sue',
'age' => '45'); %john = (
'name' =>'John',
'age' =>'20'); %peggy = (
'name' => 'Peggy',
'age' =>'16'); @children = (\%john,\%peggy);
$sue{'child'} = \@children; print $sue{'child'}->[0]->{age};
print "\n";
print %sue;
print "\n"; $sue{'child'}->[0]->{age}=99;
print $sue{'child'}->[0]->{age};
print "\n";
Vsftp:/root/perl/10# perl a14.pl
20
nameSuechildARRAY(0x1e356a8)age45
99 最后的缩写:省去两个下表间的箭头: Vsftp:/root/perl/10# cat a15.pl
%sue = (
'name' => 'Sue',
'age' =>'45',
'children' =>[
{
'name' =>' John',
'age' =>'20'
},
{'name' =>'Peggy',
'age' =>'16'
}
]
);
print %sue;
print "\n";
Vsftp:/root/perl/10# perl a15.pl
nameSuechildrenARRAY(0x1f01648)age45 引用的查询:

<1>数据引用与匿名存储的更多相关文章

  1. 数据引用Data References

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  2. [SAP ABAP开发技术总结]数据引用(data references)、对象引用(object references)

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  3. java数据的5种存储位置(转)

    任何语言所编写的程序,其中的各类型的数据都需要一个存储位置,java中书的存储位置分为以下5种: 1.寄存器 最快的存储区,位于处理器内部,但是数量及其有限.所以寄存器根据需求自动分配,无序人为控制. ...

  4. 亿级用户下的新浪微博平台架构 前端机(提供 API 接口服务),队列机(处理上行业务逻辑,主要是数据写入),存储(mc、mysql、mcq、redis 、HBase等)

    https://mp.weixin.qq.com/s/f319mm6QsetwxntvSXpKxg 亿级用户下的新浪微博平台架构 炼数成金前沿推荐 2014-12-04 序言 新浪微博在2014年3月 ...

  5. Android数据的四种存储方式SharedPreferences、SQLite、Content Provider和File (一) —— 总览

    Android数据的四种存储方式SharedPreferences.SQLite.Content Provider和File (一) —— 总览   作为一个完成的应用程序,数据存储操作是必不可少的. ...

  6. Android数据的四种存储方式SharedPreferences、SQLite、Content Provider和File (三) —— SharePreferences

    除了SQLite数据库外,SharedPreferences也是一种轻型的数据存储方式,它的本质是基于XML文件存储key-value键值对数据,通常用来存储一些简单的配置信息.其存储位置在/data ...

  7. Android数据的四种存储方式SharedPreferences、SQLite、Content Provider和File (四) —— ContentProvider

    ContentProvider是安卓平台中,在不同应用程序之间实现数据共享的一种机制.一个应用程序如果需要让别的程序可以操作自己的数据,即可采用这种机制.并且此种方式忽略了底层的数据存储实现,Cont ...

  8. Android数据的四种存储方式SharedPreferences、SQLite、Content Provider和File (二) —— SQLite

    SQLite是一种转为嵌入式设备设计的轻型数据库,其只有五种数据类型,分别是: NULL: 空值 INTEGER: 整数 REAL: 浮点数 TEXT: 字符串 BLOB: 大数据 在SQLite中, ...

  9. 使用vlookup嵌套INDIRECT函数实现跨表数据引用

    这是一个使用 vlookup 函数嵌套 INDIRECT 函数来实现跨工作表数据引用的教程. 某小学决定要抽查本校三年级三个班的期末考情况,抽查方法为在每个班中抽查5名学生,将这15名学生的期末考情况 ...

随机推荐

  1. Java 链式编程

    这里来做一个Java 链式编程的例子,基本就是每次返回一个对象本身,这样就能够去调用对象的方法和属性. package com.sun; public class Demo05 { /** * @pa ...

  2. ASC码 .

    有些时候需要用到一些字符的ASC码,到网上查找太麻烦,现在记录下来. 第128-255号为扩展字符(不常用) Dec Hx Oct Char   Dec Hx Oct Char Dec Hx Oct ...

  3. Servlet相关接口和Servlet的生命周期

    http://www.cnblogs.com/luotaoyeah/p/3860292.html Servlet相关接口和Servlet的生命周期 创建一个Servlet类最直接的方式是实现javax ...

  4. 安装aptana插件报Error opening the editor. java.lang.NullPointerException

    Aptana的官方网站下载eclipse的插件:  http://update.aptana.com/update/studio/3.2/ ,可以在线安装也可以下载插件后再安装,我是以在线的形式安装的 ...

  5. 静态库的pdb

    静态库也会有pdb,只不过,默认是以vc编译器作为名字,比如vs2003的lib的pdb是vc70.pdb,vs2008则是vc90.pdb

  6. Java源代码分析与生成

    源代码分析:可使用ANTLRANTLR是开源的语法分析器,可以用来构造自己的语言,或者对现有的语言进行语法分析. JavaParser 对Java代码进行分析 CodeModel 用于生成Java代码 ...

  7. HHVM简介(译)

    原文链接:http://coderoncode.com/2013/07/24/introduction-hhvm.html “HHVM(HIpHop Virtual Machina)把PHP代码转换成 ...

  8. CI源码学习 一步一步重写 CodeIgniter 框架

    文章:http://www.cnblogs.com/zhenyu-whu/archive/2013/08.html

  9. php获取文件mime类型Fileinfo等方法

    前几天写到使用wordpress xmlrpc api远程发布文章,如果本地服务器的文章库里某一篇待发表的wordpress文章包含图片文件时,就会使用到WordPress上传文件的API metaW ...

  10. Omnithreadlibary学习(3)-IOmniTask异步执行SendMessage

    在任务中发送消息, 可以是函数或者对象方法 TOmniTaskMessageEvent = procedure(const task: IOmniTaskControl; const msg: TOm ...