作者flu (Crazy Rhythm)
看板Perl
标题Re: [请益] 请问 perl 处理行的移动
时间Tue Feb 26 07:28:00 2013
:
: this is
: a book
: that is a chair
:
: 用 perl 改成 ==>
: this is a book
:
: that is a chair
: --------------------
:
→ gugod:把 \n 换成空白即可。 s/(this is)\n/$1 /; 02/23 17:48
→ heyk1:请问我目前只能寻找到关键字that, 然後再对那行处理 02/24 11:27
→ heyk1:打错..应是寻找关键字 book, 然後把有 book 那行往上一行移 02/24 11:29
→ heyk1:把 a book 附加在 this is 这上一行的最後面 02/24 11:30
→ heyk1:最後两行合并成同一行 02/24 14:52
推 dryman:s/\n(a book)/ \1/m; 这样就行了 02/24 16:01
→ heyk1:不好意思~小弟是菜鸟,能否解释一下 \1/m 的意思? thanks! 02/24 18:39
http://perl.hcchien.org/ch08.html 找"$1" 会找到说明 (不是找\1)
用{}内这一串去google可以找到....
{modifier 常规表示法 OR 正规表示式 OR "regular expression"}
http://knowledge.twisc.ntust.edu.tw/doku.php?id=3伺服端安全:3-3安
全程式码写作:php:在PHP使用正规表示式 (请手动还原断行)
找/m 会找到说明
: → heyk1:今天试了还是没法.因为要读一个档案, 然後跨行搜寻. 02/25 21:20
: → heyk1:但是用 while 处理, 一次只能处里一行, 无法跨行. 02/25 21:21
: → heyk1:请问有没有高手可以帮忙解答一下 Orz... thanks. 02/25 21:21
根据
http://renylai.blogbus.com/logs/27336279.html
改 $/ ($INPUT_RECORD_SEPARATOR) 可以达成整个档案的内容一次读入的效果
或者
open INPUT_FILE, '<', "/path/filename";
my @lines = <INPUT_FILE>;
my $in_one_line = join( "", @lines);
以上的所有函数、变数、正规表示式的modifiers等等
都在perldoc.perl.org有完整英文说明
例如
http://perldoc.perl.org/perlre.html#Modifiers
中文的资源我也建议找Learning Perl这本书来看
不管中英文,熟悉一些术语做网路搜寻或者沟通会比较精准
另外个人觉得发问附上足够的code比较能提高回答的动机
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 36.234.218.102
※ 编辑: flu 来自: 36.234.218.102 (02/26 07:33)
1F:推 heyk1:谢谢您详尽回答, 我会再努力写看看. thanks!! 02/26 17:39