[問題] 關於插入空行

看板Perl作者 (薰)時間17年前 (2008/05/22 17:30), 編輯推噓1(105)
留言6則, 2人參與, 最新討論串1/1
現在有個檔案~因為格式的關係 想要在第21行插入三行空白行 有辦法可以做嗎??? 因為我現在插入空行的方式,他會讓每一行中間都隔了三行 謝謝大家指教~ chdir "c:\\Perl\\Cp"; @muti=glob("*.t*"); foreach (@muti) { open (FILE,$_); @file=<FILE>; close FILE; foreach $file(@file) { open f,">>c:\\Perl\\Cp\\new\\$_"; $no=10; while(chomp $file){ if($file!~/^\d\d\s/){ for (reverse @array){ print f $no++; print f "\n\n\n"; print f " ".$_.$/ ; } print f "$file\n" ; undef @array; next ; } undef @s_line; push @s_line,reverse@{[split//,$file]}[2..$#{[split//,$file]}]; push @array,join('',@s_line); } } } close f; -- 出清衣櫃中~~歡迎參觀 http://class.ruten.com.tw/user/index00.php?c=&m=&o=&p=&s=jwce1021 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.65.55.161

05/22 17:37, , 1F
please show your code
05/22 17:37, 1F
※ 編輯: handsomegirl 來自: 61.65.55.161 (05/22 17:44)

05/22 17:44, , 2F
不好意思~附上code了
05/22 17:44, 2F

05/22 20:50, , 3F
你把印3行寫在迴圈裡了呀....
05/22 20:50, 3F

05/22 20:51, , 4F
寫個counter在外頭 做一次就+1
05/22 20:51, 4F

05/22 20:52, , 5F
再寫個if當counter=20才會印那3行空白就好了
05/22 20:52, 5F

05/23 09:28, , 6F
感恩~~~
05/23 09:28, 6F
文章代碼(AID): #18DJqrvI (Perl)
文章代碼(AID): #18DJqrvI (Perl)