亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
123下一頁
最近訪問板塊 發(fā)新帖
查看: 3179 | 回復(fù): 20
上一主題 下一主題

還是跑來求幫助了... [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2013-05-02 07:22 |只看該作者 |倒序?yàn)g覽
第一題吧:
Write a Perl program P1.pl to greet whatever is passed to it on the command line,
e.g.,
Hello, stranger!
There can be a problem with the above script: a parameter must be supplied, otherwise we'll get an error message.

comp315@turing> ./P1.pl
Use of uninitialized value $thing in concatenation (.)
or string at ./P1.pl line 4.
Hello, !
You should write the script in such a way that it will print a default value, let's say
\world", if no value is supplied on the command line.
comp315@turing> ./P1.pl
Hello, world!
Pay attention when providing zero as a parameter, as the greeting should be
comp315@turing> ./P1.pl 0
Hello, 0!
Modify the script to say \Goodbye" according to whether the -b switch was used on
the command line and the corresponding comment will be the output:
>P1.pl                             # Hello, world!
>P1.pl student                # Hello, student!
>P1.pl -b                        # Goodbye, world!
>P1.pl -b 'nice student'   # Goodbye, nice student!


第二題吧, 改錯(cuò)這個(gè)我沒怎么看懂有誰能幫我看看咩
The following program is supposed to read text from standard input and to output
them sorted by length. The lines are read in an array called @lines. Based on
@lines, a new array @sortarray is created such that each element of this array is the
length of a line of text, concatenated with the vertical bar `|' character, concatenated
with the index of that line of text in the original array @lines. The program sorts
the new array, and then uses the results to display the original lines in sorted order.

#!/usr/bin/perl
use strict;
use warnings;

my @lines;
my @sortarray;
# read in the entire input
@lines = <STDIN>;

#construct the array with the length prepended
foreach (0 .. $#lines) {
  $sortarray[$_] = length($lines[$_]) . "|" . $_;
}

# sort using numeric comparison
@sortarray = sort { $a <=> $b } @sortarray;

# display results
print "****************************************\n";
foreach (@sortarray) {
  print $lines[substr($_, index($_, "|"))];
}



論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2013-05-02 21:14 |只看該作者
請問第一題可不可以使用module

論壇徽章:
0
10 [報(bào)告]
發(fā)表于 2013-05-03 09:22 |只看該作者
#!/usr/bin/perl
use strict;
use warnings;

my $person ='world';
if( @ARGV)
{
$person = $ARGV[0];
}
print "Hello ".$person," ! \n";
這是我寫的東西...
好像沒有用到回復(fù) 2# afukada


   

論壇徽章:
7
戌狗
日期:2013-12-15 20:43:38技術(shù)圖書徽章
日期:2014-03-05 01:33:12技術(shù)圖書徽章
日期:2014-03-15 20:31:17未羊
日期:2014-03-25 23:48:20丑牛
日期:2014-04-07 22:37:44巳蛇
日期:2014-04-11 21:58:0915-16賽季CBA聯(lián)賽之青島
日期:2016-03-17 20:36:13
11 [報(bào)告]
發(fā)表于 2013-05-03 12:23 |只看該作者
本帖最后由 rubyish 于 2013-05-03 09:02 編輯

第一題:
  1. #!/usr/bin/perl
  2. use 5.016;
  3. @ARGV = map { $_ // 'world' } @ARGV[ 0, 1 ];
  4. my @greet = ( "Hello, $ARGV[0]!", "Goodbye, $ARGV[1]!" );
  5. say $greet[ $ARGV[0] eq '-b' ];
復(fù)制代碼

論壇徽章:
7
戌狗
日期:2013-12-15 20:43:38技術(shù)圖書徽章
日期:2014-03-05 01:33:12技術(shù)圖書徽章
日期:2014-03-15 20:31:17未羊
日期:2014-03-25 23:48:20丑牛
日期:2014-04-07 22:37:44巳蛇
日期:2014-04-11 21:58:0915-16賽季CBA聯(lián)賽之青島
日期:2016-03-17 20:36:13
12 [報(bào)告]
發(fā)表于 2013-05-03 15:15 |只看該作者
第二題:
改錯(cuò)
  1. my @sortarray;
  2. my @lines = <>;
  3. for ( 0 .. $#lines ) {
  4.     my $l = length $lines[$_];
  5.     $sortarray[$_] = [ $l, $l . "|" . $_ ];
  6. }
  7. @sortarray = map { $_->[1] } sort { $a->[0] <=> $b->[0] } @sortarray;

  8. print "****************************************\n";
  9. for (@sortarray) {
  10.     print $lines[ substr( $_, index( $_, "|" ) + 1 ) ];
  11. }
復(fù)制代碼
改寫:

  1. my @lines = <>;
  2. print "****************************************\n";
  3. print map { $_->[1] } sort { $a->[0] <=> $b->[0] } map [ length, $_ ], @lines;
復(fù)制代碼

論壇徽章:
0
15 [報(bào)告]
發(fā)表于 2013-05-04 14:25 |只看該作者
話說 改錯(cuò)這個(gè) 沒怎么看懂.....回復(fù) 12# rubyish


   

論壇徽章:
7
戌狗
日期:2013-12-15 20:43:38技術(shù)圖書徽章
日期:2014-03-05 01:33:12技術(shù)圖書徽章
日期:2014-03-15 20:31:17未羊
日期:2014-03-25 23:48:20丑牛
日期:2014-04-07 22:37:44巳蛇
日期:2014-04-11 21:58:0915-16賽季CBA聯(lián)賽之青島
日期:2016-03-17 20:36:13
16 [報(bào)告]
發(fā)表于 2013-05-06 13:55 |只看該作者
回復(fù) 13# babyma1109


    一個(gè)簡潔優(yōu)雅的代碼 ...非常簡短。

  1. my @a = map { $_ // 'world' } @ARGV[ 0, 1 ];
  2. say $a[0] ne '-b' ? "Hello, $a[0]!" :  "Goodbye, $a[1]!"
復(fù)制代碼

論壇徽章:
1
15-16賽季CBA聯(lián)賽之北控
日期:2016-08-05 14:22:52
17 [報(bào)告]
發(fā)表于 2013-05-10 14:53 |只看該作者
回復(fù) 16# rubyish


   請教一下  $_ // 'world' 是什么意思啊

論壇徽章:
7
戌狗
日期:2013-12-15 20:43:38技術(shù)圖書徽章
日期:2014-03-05 01:33:12技術(shù)圖書徽章
日期:2014-03-15 20:31:17未羊
日期:2014-03-25 23:48:20丑牛
日期:2014-04-07 22:37:44巳蛇
日期:2014-04-11 21:58:0915-16賽季CBA聯(lián)賽之青島
日期:2016-03-17 20:36:13
18 [報(bào)告]
發(fā)表于 2013-05-11 09:00 |只看該作者
回復(fù) 17# 唐歸來
  1. $_ // 'world' 是什么意思啊
復(fù)制代碼
  1. defined $_ ? $_ : 'world'
復(fù)制代碼

論壇徽章:
0
21 [報(bào)告]
發(fā)表于 2013-05-13 08:51 |只看該作者
不愧是大神級別的  比我這種屌絲寫的好多了回復(fù) 20# ypqfyf


   

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2013-05-02 23:52 |只看該作者
回答了題是不是可以推薦工作?
sinian126 該用戶已被刪除
4 [報(bào)告]
發(fā)表于 2013-05-03 08:06 |只看該作者
提示: 作者被禁止或刪除 內(nèi)容自動屏蔽

論壇徽章:
7
戌狗
日期:2013-12-15 20:43:38技術(shù)圖書徽章
日期:2014-03-05 01:33:12技術(shù)圖書徽章
日期:2014-03-15 20:31:17未羊
日期:2014-03-25 23:48:20丑牛
日期:2014-04-07 22:37:44巳蛇
日期:2014-04-11 21:58:0915-16賽季CBA聯(lián)賽之青島
日期:2016-03-17 20:36:13
5 [報(bào)告]
發(fā)表于 2013-05-03 08:41 |只看該作者
NaN!!{:3_188:}{:3_188:}

論壇徽章:
0
6
發(fā)表于 2013-05-03 08:50
第一題 我只寫出了第一部分....
怎么加-b讓他交換就不太明白了
回復(fù) 2# afukada


   

論壇徽章:
0
7 [報(bào)告]
發(fā)表于 2013-05-03 08:53 |只看該作者
哈哈  想太多了  回答了就能寫作業(yè)了
回復(fù) 3# Perlvim


   

論壇徽章:
0
8 [報(bào)告]
發(fā)表于 2013-05-03 08:54 |只看該作者
這個(gè)  話說我也是  可是米有辦法
回復(fù) 4# sinian126


   

論壇徽章:
0
9
發(fā)表于 2013-05-03 08:55
老師還說...你要想拿extra point, 就要把甚么格式寫的好看點(diǎn)啊
如果人家輸入的是-c 你要告訴別人只能是-b才行甚么的  
很是頭大啊回復(fù) 5# rubyish


   
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP