According to Beginning Perl Book published by Tsinghua Pub., the list context appears when you are trying to assign some value to a list variable.

 my @copy = @source;

This is a very simple instance of shallow copy, which usually means you just copied the reference of the source array, none new elements are created and no other memories will be occupied.

  When we assign an array with a hash table, the key-value elements will be converted to a plain list, which is called planarization.

  For example, the following perl codes will print the result below:

 my %hashtable = (
Tom=>,
Jerry=>,
Sam=>
);
my @flattened = %hashtable;
print @flattened;
Tom12Jerry13Sam17

*Another thing I want to stress here is, if we want to seperate these flattened elements by a blank space charactor, we need to modify the print statement to this: (Attention to the quatation marks)

 print "@flattened";

Thus, the result in console will become:

Tom 12 Jerry 13 Sam 17

The book has noted one important feature - the advantage of list context:

You can force to obtain it with a pair of brackets.

If we want to assign the first element to a scalar variable, we can simply surround it with brackets, like this:

 my @array = ('element0','element1');
my ($scalar) = @array;
print $scalar;

  The result is displayed:

element0

  But there is more than that! We can add more scalars to the brackets(as long as the array has enough elements), and the scalars will be assigned by the elements one by one. Code it as follow:

 my @array = ('element0','element1');
my ($scalar0,$scalar1);
print "$scalar0\t$scalar1";

  The result is:

element0    element1

  Have you found the advantage of list context? If you haven't, see the followint statement:

($leftScalar , $rightScalar) = ($rightScalar , $leftScalar);

  Isn't it beautiful? Usually, especially in some other languages, we have to use a third variable to store one of the two elements and that certainly takes more than this in Perl.

  

  OK! It's what we get this afternoon!

Several Ideas on Perl List Context的更多相关文章

  1. Nginx - HTTP Configuration, Module Directives

    Socket and Host Configuration This set of directives will allow you to configure your virtual hosts. ...

  2. Pattern Recognition and Machine Learning-02-1.0-Introduction

    Introduction The problem of searching for patterns in data is a fundamental one and has a long and s ...

  3. [转载]两个半小时学会Perl

    Learn Perl in about 2 hours 30 minutes By Sam Hughes Perl is a dynamic, dynamically-typed, high-leve ...

  4. 在vi中使用perltidy格式化perl代码

    格式优美的perl代码不但让人赏心悦目,并且能够方便阅读. perltidy的是sourceforge的一个小项目,在我们写完乱七八糟的代码后,他能像变魔术一样把代码整理得漂美丽亮,快来体验一下吧!! ...

  5. Perl技巧

    项目里面一直用的是Perl,Perl里有各种小技巧就分享在这吧. push(@a, $b) 把b元素压入a数组中, 还可以有 push(@a, [@b]); 那a就成了二维数组了 scalar(@a) ...

  6. PCRE Perl Compatible Regular Expressions Learning

    catalog . PCRE Introduction . pcre2api . pcre2jit . PCRE Programing 1. PCRE Introduction The PCRE li ...

  7. perl脚本基础总结

    1.  单引号字符串中的\n不会被当做换行符处理. 如:'\'\\'  -->  '\  . 2.  双引号 字符串联    "Hello"."World" ...

  8. 34 Sources for Test Ideas

    We recommend collecting test ideas continuously from a variety of information sources. Consider the ...

  9. Perl参考函数

    这是标准的Perl解释器所支持的所有重要函数/功能的列表.在一个函数中找到它的详细信息. abs - 绝对值函数 accept - 接受传入的socket连接 alarm - 调度一个SIGALRM ...

随机推荐

  1. 【Hexo】deploy出错的解决方法

    .ERROR Deployer not found: git 执行npm install hexo-deployer-git --save .$ hexo d INFO Deploying: git ...

  2. [Jxoi2012]奇怪的道路 题解(From luoguBlog)

    题面 状压好题 1<= n <= 30, 0 <= m <= 30, 1 <= K <= 8 这美妙的范围非状压莫属 理所当然地,0和1代表度的奇偶 dp[i][j ...

  3. 竞品分析」项目协作管理平台-Teambition和CORNERSTONE--深度体验

    一.分析目的 通过分析2B产品中的团队协作管理软件的对比分析,用于为公司团队协作软件的选型做产考. 二.竞品归属市场概况 2.1.目标用户群及需求 主要面向企业用户,用于解决企业不同地域以及不同职能部 ...

  4. python tips:类的绑定方法(bound)和非绑定方法(unbound)

    类属性只有类及其实例能够访问,可以理解为一个独立的命名空间. Python中类属性的引用方式有两种: 1. 通过类的实例进行属性引用,称为绑定方法(bound method),可以理解为方法与实例绑定 ...

  5. Linux direct io使用例子

    Linux direct io使用 在linux 2.6内核上使用direct io不难,只需按照如下几点来做即可: 1,在open文件时加上O_DIRECT旗标,这样以通告内核我们想对该文件进行直接 ...

  6. [转]理解和配置 Linux 下的 OOM Killer

    最近有位 VPS 客户抱怨 MySQL 无缘无故挂掉,还有位客户抱怨 VPS 经常死机,登陆到终端看了一下,都是常见的 Out of memory 问题.这通常是因为某时刻应用程序大量请求内存导致系统 ...

  7. [poj1325] Machine Schedule (二分图最小点覆盖)

    传送门 Description As we all know, machine scheduling is a very classical problem in computer science a ...

  8. 实体服务器安装centos7过程记录

    一次在实体服务器安装centos 7的过程记录 第一次在实体服务器上面安装服务器(centos 7),在此记录安装过程中遇到的一些坑. 系统版本:CentOS Linux release 7.6.18 ...

  9. js中二维数组的创建方法 2017-04-04 14:50 120人阅读 评论(0) 收藏

    法一:var myarr=[[0,1,2],[1,2,3]]; 将[0,1,2]看做原来的0,将[1,2,3]看做原来的1,而二者又分别为子数组 如myarr[0][1]=1,myarr[1][1]= ...

  10. 基于SSH的J2EE Web系统配置文件

    1. web.xml 关于Servlet Servlet是一个特殊的Java类,Servlet可以输出HTML标签作为表现层使用,但自从MVC规范出来以后,明确了Servlet的指责仅作为控制器使用, ...