Perl 自增问题
来源:互联网 发布:淘宝网品牌 编辑:程序博客网 时间:2024/06/06 07:19
<pre name="code" class="sql">[root@june3 ~]# cat 2.shfor((i=1;i<=10;i++))doecho $idoneecho "last \$i is $i\n";[root@june3 ~]# sh ./2.sh12345678910last $i is 11\n$i最后的值是11----------------------------------------------------------------[root@june3 ~]# cat a2.pl %log;foreach (1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,5,6) {print "1---\$log{$_} is $log{$_} \n";###添加hash 数组元素$log{$_}++;print "2---\$log{$_} is $log{$_} \n";};while(my($ip, $times) = each %log) { print "$ip $times\n"; }print "1--------$log{1}\n";print "2--------$log{2}\n";[root@june3 ~]# perl a2.pl 1---$log{1} is 2---$log{1} is 1 1---$log{1} is 1 2---$log{1} is 2 1---$log{1} is 2 2---$log{1} is 3 1---$log{2} is 2---$log{2} is 1 1---$log{2} is 1 2---$log{2} is 2 1---$log{2} is 2 2---$log{2} is 3 1---$log{2} is 3 2---$log{2} is 4 1---$log{2} is 4 2---$log{2} is 5 1---$log{2} is 5 2---$log{2} is 6 1---$log{3} is 2---$log{3} is 1 1---$log{3} is 1 2---$log{3} is 2 1---$log{3} is 2 2---$log{3} is 3 1---$log{3} is 3 2---$log{3} is 4 1---$log{3} is 4 2---$log{3} is 5 1---$log{3} is 5 2---$log{3} is 6 1---$log{4} is 2---$log{4} is 1 1---$log{5} is 2---$log{5} is 1 1---$log{6} is 2---$log{6} is 1 6 14 11 33 62 65 11--------32--------6hash 数组添加元素:元素赋值与操作: 增加: 赋值$h{'a'}=1,不存在则创建,hash不存在也创建。%log;foreach (1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,5,6) {print "1---\$log{$_} is $log{$_} \n";###添加hash 数组元素$log{$_}++;print "2---\$log{$_} is $log{$_} \n";};while(my($ip, $times) = each %log) { print "$ip $times\n"; }print "1--------$log{1}\n";print "2--------$log{2}\n";相当于:foreach (1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,5,6) {#print "1---\$log{$_} is $log{$_} \n";$log{'$_'}=$log{$_}++;};while(my($ip, $times) = each %log) { print "$ip $times\n"; }print "1--------$log{1}\n";print "2--------$log{2}\n";hash数组添加元素;my %hash = ("1","a", "2","b");foreach $key (sort keys %hash){ $var = $hash{$key}; print "$key is $var\n";}print "----------------------------\n";##add$hash{3}++;foreach $key (sort keys %hash){ $var = $hash{$key}; print "$key is $var\n";}print "----------------------------\n";$hash{3}++;foreach $key (sort keys %hash){ $var = $hash{$key}; print "$key is $var\n";}[root@june3 ~]# perl a5.pl 1 is a2 is b----------------------------1 is a2 is b3 is 1----------------------------1 is a2 is b3 is 2
0 0
- Perl 自增问题
- 自增自减问题
- 自增自减问题
- Perl 问题
- 多线程自增问题
- perl调试,直接用perl自带的debugger
- Perl语言入门(09 perl中自带的函数)
- perl 解答奶油问题
- Perl 的排序问题
- Perl中的编码问题
- perl一些问题
- perl中一些问题
- perl 乱码问题
- perl关于乱码问题!
- oo perl 继承问题
- Perl 的排序问题
- Perl语言问题
- 解决perl编译问题
- 结构体对齐问题
- Spring的FetchType
- Line输入和mic输入的区别
- 欧拉四面体公式
- [NLP] 命名实体识别简要知识点
- Perl 自增问题
- ViewController
- LeetCode 138. Copy List with Random Pointer
- UVA 10167 Birthday Cake
- unix的历史
- Android3.0 上的磁盘加密 Notes on the implementation of encryption in Android 3.0
- 只言片语
- Cocos3.4 横版游戏制作-《KillBear》-暂停层+屏蔽下层监听
- leetcode 日经贴,python code -Remove Duplicates from Sorted Array