作者giacch (小a)
看板Perl
標題Re: [問題]新手問題
時間Fri Sep 19 01:19:41 2008
※ 引述《yingwan (yingwan)》之銘言:
: 大家好
: 剛接觸perl第二個禮拜,老師出的一個問題我一直卡著,所以上來請教各位前輩
: 我們老師要我們寫出一個指令,先問喜歡的顏色,再依照對方回答排出以下圖案
: red red red red red red red red red red
: red red
: red red
: red red red red red red red red red red
: 問題就在,我用red測試OK,但是如果用blue 就會變成
: blue blue blue blue blue blue blue blue blue blue
: blue blue
: blue blue
: blue blue blue blue blue blue blue blue blue blue
: 可是我希望是
: blue blue blue blue blue blue blue blue blue blue
: blue blue
: blue blue
: blue blue blue blue blue blue blue blue blue blue
: 我把我的步驟貼在下面,希望有前輩可以指點我一下,謝謝
#!usr/bin/perl -w
print "What is your favorite color?\n ";
$a=<STDIN>;
chomp $a;
#$b= ($a ." " . $a. " ") x 5 ;
$b = $a . " $a" x 9;
#$c= $a . "\t" x 5 . $a;
$c = $a . " " x (length(" $a") * 9) . " $a";
print "$b\n";
print "$c\n";
print "$c\n";
print "$b\n";
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.232.236.185
推 yingwan:感謝大大,我昨天解出來了,我用\t加" " 09/19 21:35
→ yingwan:再乘以$a長度 09/19 21:37