learning perl第5章練習問題
6182 ワード
原文在网易博客2010-11-16 13:39:42
learning perl第5章の練習問題は少し予想外で、第5章は基本的な入出力を話していましたが、練習問題を実現するのに時間を費やして前のいくつかの章を振り返ってみました.ほほほ、配列の知識も使いました.
第1題:
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
第3題:
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
2011-05-25 00:58最近perlを見ていません.この言語は不思議な言語で、同じ変数で、異なる文脈の中に置いて、表現の意味は全然違います.perlの理解と使用を安定させるには、毎週少し時間がかかります.さもないと忘れやすい.ええ、少なくともc、javaなどより忘れやすいです.
learning perl第5章の練習問題は少し予想外で、第5章は基本的な入出力を話していましたが、練習問題を実現するのに時間を費やして前のいくつかの章を振り返ってみました.ほほほ、配列の知識も使いました.
第1題:
1: #!perl -w
2: #tac
3: use strict;
4: use 5.10.1;
5: my @result;
6: #@ARGV=qw(test1.txt test2.txt);
7: while(<>){
8: chomp($_);
9: push (@result,$_);
10: }
11: while(@result){
12: say pop (@result);
13: }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
第3題:
1: #!perl -w
2: sub printRuler{
3: if(@_ != 1){
4: print "should have one argument.
";
5: return;
6: }
7:
8: my $index=1;
9: my $count=$_[0];
10: my $current=0;
11:
12: if( $count < 0){
13: $count =0;
14: }
15:
16: while($current <$count){
17: print "$index";
18: $index++;
19: if($index == 10 ){
20: print "0";
21: $index=1;
22: $current++;
23: }
24:
25:
26: }
27: print "
";
28: }
29: sub printString{
30: &printRuler(5);
31: my $length=shift @_;
32: my $format="%${length}s
";
33: while(@_){
34: printf $format,$_[0];
35: shift @_;
36: }
37: }
38: my @hi=qw(30 hello good-bye);
39: &printString(@hi);
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
2011-05-25 00:58最近perlを見ていません.この言語は不思議な言語で、同じ変数で、異なる文脈の中に置いて、表現の意味は全然違います.perlの理解と使用を安定させるには、毎週少し時間がかかります.さもないと忘れやすい.ええ、少なくともc、javaなどより忘れやすいです.