加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Perl练习

发布时间:2020-12-16 00:11:41 所属栏目:大数据 来源:网络整理
导读:#!/usr/bin/perl=this is a describe$word="Hello "."World"."n";$newWord=$word x 4;print $newWord; $num=3;$num+=2;print $num,"n";print "the answer is ",6*7,"n";print "num value is $num n";$line=STDIN;if ($line eq "n"){print "your input i
#!/usr/bin/perl
=this is a describe
$word="Hello "."World"."n";
$newWord=$word x 4;
print $newWord; 
$num=3;
$num+=2;
print $num,"n";
print "the answer is ",6*7,"n";
print "num value is $num n";


$line=<STDIN>;
if ($line eq "n"){
	print "your input is a blank n"
}
else{
	print "your input is $line n"
}
=cut
chomp($text=<STDIN>);
#$text=<STDIN>;
print $text;


?

#!/usr/bin/perl 
$pi=3.1425926;
chomp($r=<STDIN>);
if($r < 0){
	$ans =0;
}else{
	$ans=2 * $pi * $r;
}
print "ans is $ans n";


?

#!/usr/bin/perl -w
print "Enter the first num : ";
chomp($firstNum=<STDIN>);
print "Enter the second num: ";
chomp($secondNum=<STDIN>);
$ans=$firstNum * $secondNum;
print "the ans is $ans n";


?

#!/usr/bin/perl -w
chomp(@lines=<STDIN>);
@afterLines=reverse(@lines);
#print @afterLines;
foreach $item (@afterLines){
	print $item,"n";
}
print "**************";
print @afterLines[1];


?

#!/usr/bin/perl -w
@value=qw(zhangzhao wangfang liming baidu wangyi);
chomp(@indexs=<STDIN>);
foreach $item (@indexs){
	print @value[$item]," ";
}
print "n";


?

#!/usr/bin/perl -w
chomp(@names=<STDIN>);
@afterSort=sort(@names);
foreach $item (@afterSort){
	print $item," ";
}
print "n";


?

#!/usr/bin/perl -w
sub totalSum{
	$sum=0;
	foreach (@_){
		$sum+=$_;
	}
	$sum;
}

@nums=1..10000;
$ans=totalSum(@nums);
print $ans;


?

#!/usr/bin/perl -w

sub above_average{
	$sum=0;
	$ave=0;
	foreach (@_){
		$sum+=$_;
	}
	$len=@_;
	$ave=$sum/$len;
	foreach(@_){
		if($_ > $ave){
			print $_,"n";
		}
	}

}
print above_average(1..30);


?

#!/usr/bin/perl -w


@arr=qw();
sub greet{
	$name=@_[0];
	push @arr,$name;
	$len=@arr;
	if( $len ==1 ){
		print "Hi $name ! you are the first one n";
	}
	else{
		$pre=shift @arr;
		print "Hi $name ! $pre is also here n";
	}
}
greet("zhangzhao");
greet("baidu");
greet("360");
greet("wangyi");


?

#!/usr/bin/perl -w


@arr=qw();
sub greet{
	$name=@_[0];
	push @arr,$name;
	$len=@arr;
	if( $len ==1 ){
		print "Hi $name ! you are the first one n";
	}
	else{
		$pre = unshift @arr;
		print "Hi $name ! I have seen @arr is also here n";
	}
}
greet("zhangzhao");
greet("baidu");
greet("360");
greet("wangyi");


?

#!/usr/bin/perl -w
$name="zhangzhao";
$name2 = reverse $name;
while(chomp($name=<STDIN>)){
	$reName=reverse $name;
	print $reName,"n";
}


=opd
while($name=<>){
	$reName=reverse $name;
	print $reName,"n";
}
=cut


?

#!/usr/bin/perl -w
my %myHash;
$myHash{"freb"}="filintston";
$myHash{"barney"}="rubble";
$myHash{"wilma"}="zhao";
chomp($name=<STDIN>);
print "value is ",$myHash{$name},"n";


?

#!/usr/bin/perl -w
#统计各个单词出现的次数
my(@words,$myHash,$word);
chomp(@words=<STDIN>);
foreach $word (@words){
	$myHash{$word}+=1;
}
foreach $word (sort keys %myHash){
	print " $word has seen $myHash{$word} times n";
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读