scalar and list context in Perl

原创 2013年12月02日 16:43:14


@people = qw(  fred barney betty);

@sorted = sort @people; #list context: barney, betty, fred

$number = 42 + @people; # scalar context :45

@list = @people; #  a list of 3 people

$n = @people;# the number 3

Force list context to scalar context:

@rocks = qw( talc q f d );

$number = @rocks;

print  " the number is :", scalar @rocks, "hello";

print  " the number is : $number hello";

above are the same

ps: there is no corresponding functions to force list context. It turns out you never need it.


What's the difference between “local” and “my” in Perl

There are two kinds of variable scopes in Perl: Global variables: They reside in the current pa...
  • ThinkHY
  • ThinkHY
  • 2012年08月30日 12:55
  • 1426

What is a Context in Java and ApplicationContext vs WebApplicationContext

当我们开始使用Spring Framework时,能想到的最基本的问题是:ApplicationContext在spring中扮演什么的角色,它和WebApplicationContext有什么不同呢...

多尺度R-CNN(2): Inside-Outside Net: Detecting Objects in Context with Skip Pooling and Recurrent Neural


Polymorphism in Perl comparing with JAVA and C++

Polymorphism in Perlcomparing with JAVA and C++ Abstract In USD daily test automation, we used Per...

FAIL - Context /SsmApp is defined in server.xml and may not be undeployed

Deploying /root/.jenkins/workspace/SsmApp/SsmApp/target/SsmApp.war to container Tomcat 7.x Remote ...

[Perl语法篇] 数据类型:标量$Scalar

标量是用于存放一个值的变量,这个值可以是数字,也可以是字符串(其实数字就是字符串)。 Perl通过变量前的“魔符”$来识别标量。...

Perl Learning 1 Scalar Data

【本文原创,转载请说明】 唉,虽然立志搞硬件,但并不是弄底层电路,需要和大量代码打交道,看到VTR-to-Bitstream中不断的用到了perl脚本语句,心血来潮地想学学,找到了Randal L....
  • manhusl
  • manhusl
  • 2015年06月19日 18:30
  • 266
您举报文章:scalar and list context in Perl