perl操作数组

#!/usr/bin/perl -w
#test the string
print "hello" ." ". "world!\n"; #字符串连接
print "hello" x 4 . "\n";
print "ha" x (2+3) . "\n";
print "12ggdd" * 3 ."\n"; #启用告警时,即#!/usr/bin/perl -w时,程序提示告警信息.
#计算从1到100的所有奇数相加.
$num=1;
#$sum=0;
while ($num < 100){
$sum+=$num;
#print $num ."\n";
$num+=2;
}
print $sum;

#test the list
#print "=============test the list=============";
#@listA= (1..100);
#foreach $item (@listA){
# print $item;
#}

#test pop method
print "\n\n";
@arr=5..9;
$fred1=pop(@arr);
$fred2=pop(@arr); #the value of $fred2 is 8.
printf "%s,%s",$fred1,$fred2;
#test push method
print "\n\n";
foreach $item (@arr){
print $item . "\n";
}
print "\n\n";
push (@arr,10); #push 一个元素10
push @arr,20; #push 一个元素20
push @arr ,1..10; #push 一个元素1..10
foreach $item (@arr){
print $item . "\n";
}

print "\n\n";
@brr=reverse(@arr);#数组元素,翻转.
foreach $item (@brr){
print $item . "\n";
}

print "\n\n";
@crr=sort(@arr);#数组元素,排序.
foreach $item (@crr){
print $item . "\n";
}

print "write some words :\n";
while(chomp($line=<STDIN>))
{
print $line ."\n";
if (lc($line) eq "yes") #lc/uc/lcfirst/ucfirst
{
print "break out !\n";
last;
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值