perl_topic3_array1

perl_topic3_array1

ID:40087261

大小:222.56 KB

页数:17页

时间:2019-07-20

perl_topic3_array1_第1页
perl_topic3_array1_第2页
perl_topic3_array1_第3页
perl_topic3_array1_第4页
perl_topic3_array1_第5页
资源描述:

《perl_topic3_array1》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库

1、3) Lists and arrays Ma. Webster IMBIM, BMC ma.hew.webster@imbim.uu.se lists and arrays •A list is an ordered set of scalar values: (1,2,3,"Matt")!!•An array is a variable that holds a list: @arr=(1,2,3,"Matt");!index 0 1 2 3 print@arr;!value 1 2 3 Ma

2、. 123Matt!!•You can access an individual array element: print$arr[1];!2!!$arr[0]="*";!print@arr;!perl starts counHng at 0 *23Matt!lists and arrays You can easily get a sub‐array: @arr=(1,2,3,"fred","bob");print@arr;!!!123fredbob!print$arr[1];!!2!my@s

3、ub_arr=@arr[1..3]print@sub_arr;!!23fred!!You can extend an array as much as you like: @arr2=(1,2,3)!$arr2[5]=6;!!!@arr2!!#is now(1,2,3,undef,undef,6)!!special array indices $students[0]="Doreen";!$students[1]="Oskar";!$students[2]="Elin";!$students[3

4、]="Sangeet";!$students[4]="Malin";!!$end=$#students;# 4, the final index print$students[$end];#same as$students[-1]!Malin!another way: @students=("Doreen","Oskar","Elin","Sangeet","Malin");!!and another way: @students=qw/DoreenOskarElinSangeetMalin/;!

5、!qwmeans quote with whitespace list literals •all these are the same: (1,2,3,4,5,6,7,8,9,10)!(1..10)!(1,2,3..9,10)!qw/12345678910/!!($i..$j)!#numbers between$iand$j!(0..$#students)#indices of@students!!qw can be used with a lot of characters: @studen

6、ts=qw/DoreenOskarElinSangeetMalin/;!@students=qw!DoreenOskarElinSangeetMalin!;!!@students=qw{DoreenOskarElinSangeetMalin};!@students=qw;!push and pop!@students=qw/DoreenOskarElinSangeetMalin/;!push!pop!$students[5]"Aaron"

7、!"Malin"!$students[4]$students[4]"Malin"!$students[3]"Sangeet"!$students[2]"Elin"!$students[1]"Oskar"!$students[0]"Doreen"!$final_student=pop(@students)!#"Malin"is removed from@studentsand placed in$final_student!!push(@students,"Aaron");!#"Aaron"is 

8、added to the end of@students!!pop@students!#"Aaron"is removed from@studentsand discarded !!push and pop!@students=qw/DoreenOskarElinSangeetMalin/;!$students[4]"Malin"!$students[3]"Sangeet"!$students[2]"Elin"!$students[1]"Oskar"!$students[0]"Doreen"!@

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。
相关文章
更多
相关标签