CU问题解答

来源:互联网 发布:如何隐藏我的淘宝订单 编辑:程序博客网 时间:2024/04/27 19:29

下面是一些CU上的问题,用shell 现实的,这里改用perl实现

1 http://bbs.chinaunix.net/thread-4068071-1-1.html

</pre><pre name="code" class="html">#!/opt/exp/bin/perl -wopen ($fd1,"<a.txt");open ($fd2,"<b.txt");@item1=();@item2=();$length1="";while ( <$fd1> ) {chomp;$str=$_;@item1=split /\t+/,$str;$hash{$item1[0]}=$str;push(@a,$item1[0]);}while ( <$fd2> ) {chomp;$str=$_;@item2=split /\t+/,$str;$length1=@item2;@item4=@item2[1...$length1-1];$str1=join ("\t",@item4);
<span style="white-space:pre"></span>#hash value can string; 标量即可$hash2{$item2[0]}=$str1;}$i=0;$l=@a;$found=0;while ($i<$l)  {#foreach $key1 (keys %hash) {foreach $key2 (keys %hash2) {#if ($key1 eq $key2) {<span style="font-family: Arial, Helvetica, sans-serif;"></span>
if ($a[$i] eq $key2) {#print $hash{$key1};print $hash{$a[$i]};print "\t";print $hash2{$key2};$found=1;last;}}if ($found==0) {print $hash{$a[$i]};}print "\n";$found=0;$i++;}

2 http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=4068465

#!/opt/exp/bin/perl -w$file="16.txt";if (! open ($fd,"<$file")) {warn "open file fail\n";return undef;}$num=0;while ( <$fd> ) {chomp;$str=$_;if ( $str =~ /^\s+(.*)/ ) {$new=$new." ".$1;} else {if ($num==0) { $new=$str;} else {$new=$new."\n";$new=$new.$str;}$num++;}}print "$new\n";

3 http://bbs.chinaunix.net/thread-4068917-2-1.html

#!/opt/exp/bin/perl -w$file="Desc.txt";if (! open ($fdr,"<$file")) {warn "open file fail";return undef;}$num=0;while ( <$fdr> ) {chomp;$str=$_;#@item1=split /, /,$str;if ( $str=~ /(^Description)(.*)/ ) {$str1=$2;}if ( $num ==0 ) {print "$str";} else {print "$str1";}$num++;}print "\n";close($fdr);


0 0
原创粉丝点击