`
weihe6666
  • 浏览: 430184 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Perl-Arrays

阅读更多
Perl-Arrays


1.在利用数组的下标时注意数组的长度,比如下面的例子:
@name = qw(fred betty barney dino wilma pebbles bamm-bamm);
print "The name is @name\n";
chmod(@index = <STDIN>);
#######################
#######################
#print the content of index
#$vari = pop (@index);
$a=@index;#获取数组的大小;
print "The value of a is $a\n";
$vari_1 = 0;
########################
[color=red]while($vari_1 <= $a){[/color]print "@index[$vari_1]" . " " ."@name[@index[$vari_1]]\n";
$vari_1 += 1;
}

输入:
3
3
4
4
2
2
输出
3
dino
3
dino
4
wilma
4
wilma
2
barney
2
barney
fred

最后一个"fred"为何也会输出??

改代码:
[color=red]while($vari_1 < $a){[/color]print "@index[$vari_1]" . " " ."@name[@index[$vari_1]]\n";
$vari_1 += 1;
}

输入:
3
3
4
4
2
2
输出
3
dino
3
dino
4
wilma
4
wilma
2
barney
2
barney
当索引超出数组大小时,Perl默认赋值为undef 即为0。
所以第一段代码会输出fred.


2.列表直接量
(1..100)  #100个整数构成的列表
(1,2,3)   #1 2 3构成的列表
比如:求1-1000的和
my @fred=(1..1000);#这里是重点
my $fred_total = total(@fred);
print "The total of \@fred is $fred_total.\n";
print "Enter some numbers on separate lines:";
sub total{
	my $vari_total = 0;
foreach(@_){
	$vari_total += $_;
	#print "$_\n";
}
$vari_total;
}

输出结果:500500
分享到:
评论

相关推荐

    Note of Learning Perl--Lists and Arrays

    NULL 博文链接:https://huanyue.iteye.com/blog/656304

    matlab导入excel代码-utl_multiple-regressions-using-arrays:使用数组的线性回归或逐行回归。关键

    matlab导入excel代码utl_...Perl CC#Excel MS Access JSON图形映射NLP自然语言处理机器学习igraph DOSUBL DOW循环stackoverflow SAS社区。 使用数组的线性回归或逐行回归 WPS PROC R/SAS (same result) github ...

    Intermediate Perl.pdf

    including arrays of arrays and hashes of hashes. Chapter 7, Subroutine References Capture behavior as an anonymous subroutine that you create dynamically and execute later. Chapter 8, Filehandle ...

    perl指令,学习perl指令必备

    PERL CGI简介及指令示范 作者: 蔡奇玉、连振汉、张志强 (2001-08-22 12:00:00) 摘自蔡奇玉、连振汉、张志强著《CGI编程指南》第六章 为尊重作者版权,只作部分节选,以作推介之用, 推荐您购买原书阅读! 6.1 Perl...

    beginning perl for bioinformatics

    Regular expressions and finding motifs in data, Arrays, hashes, and relational databases, Regular expressions and restriction maps, Using Perl to parse PDB records, annotations in GenBank, and BLAST ...

    perl_爬虫脚本

    银行外汇牌价爬虫。结合中英两版网站信息,适合perl初学者学习模块和... Binding ounce version of the site information for beginners to learn perl module and hash arrays, etc. Txt file format code in them.

    Beginning Perl for Bioinformatics

    Regular expressions and finding motifs in data, Arrays, hashes, and relational databases, Regular expressions and restriction maps, Using Perl to parse PDB records, annotations in GenBank, and BLAST ...

    Using Perl For Web Programming.pdf

    Using Perl for Web Programming David Harlan, et al. CONTENTS Chapter 1 Perl Overview Perl Origins H Borrowings H Cost and Licensing H Distribution H G Perl Programs Invocation H Command-Line ...

    Write Great Code Volume I

    You’ll learn how to work with strings, numbers, lists, arrays, strictures, namespaces, regular expressions, subroutines, references, distributions, inline code, warnings, Perl::Tidy, data munging, ...

    Modern Perl_en.pdf

    Arrays........................................................... 36 Hashes........................................................... 40 Coercion.........................................................

    Awk入门教程 《Awk A Tutorial and Introduction - by Bruce Barnett》

    Awk入门教程。作者 Bruce Barnett 注:英文版。以下是目录 Why learn AWK? Basic Structure Executing an AWK script Which shell to use with AWK? Dynamic Variables ...AWK, NAWK, GAWK, or PERL

    Beginning Java 9 Fundamentals Arrays, Objects, Modules, JShell, and Regular epub

    Beginning Java 9 Fundamentals Arrays, Objects, Modules, JShell, and Regular Expressions 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn...

    perl_list_helpers_xs:该模块提供了几种方法来从数组中随机抽取和获取随机元素

    perl_list_helpers_xs姓名List::Helpers::XS - Perl extension to provide some usefull functions with arrays概要 use List::Helpers::XS qw/ :shuffle :slice / ; my @slice = random_slice(\ @list , $size ); ...

    Json-lib 是一个 Java 类库

    JSON 采用完全独立于语言的文本格式,但是也使用了类似于 C 语言家族的习惯(包括C, C++, C#, Java, JavaScript, Perl, Python等)。 这些特性使 JSON 成为理想的数据交换语言。 •JSON 的两种结构 1.“名称/值”...

    Ruby程序中正则表达式的基本使用教程

    主要有strings,integers,floats,arrays等等。然而,只有脚本语言,如Ruby,Perl,和awk等提供了内置表达式类型的支持。正则表达式尽管比较隐蔽,但却是一个很强大的文本处理工具。 正则表达式是使用指定的模式...

    2009 达内Unix学习笔记

    集合了 所有的 Unix命令大全 ...telnet 192.168.0.23 自己帐号 sd08077-you0 ftp工具 192.168.0.202 tools-toolss ... 各个 shell 可互相切换 ksh:$ sh:$ csh:guangzhou% bash:bash-3.00$ ... 命令和参数之间必需用空格隔...

    类似C的脚本语言little-lang.zip

    特征:与C语言语法相似Structs, lists, arrays, hashesPerl 的正则表达式: buf =~ /.*foo/, I/O: while (buf = )没有内存管理(引用计数)编译到Tcl的字节代码,little-lang可以调用的Tcl,TCL可以调用little-lang...

    Programming Microsoft LINQ in Microsoft.NET Framework 4

    .NET 4, Types, Arrays, Exception Handling LINQ, Object/Collection Initializers OOP: Classes, Objects, Inheritance, Polymorphism, Interfaces WinForms, WPF, XAML, Event Handling WPF GUI/Graphics/...

    C# 2010 for Programmers 4ed part1

    .NET 4, Types, Arrays, Exception Handling LINQ, Object/Collection Initializers OOP: Classes, Objects, Inheritance, Polymorphism, Interfaces WinForms, WPF, XAML, Event Handling WPF GUI/Graphics/...

Global site tag (gtag.js) - Google Analytics