in reply to Efficiency issues in text parsing
in thread replacing text in specific tags
here is the input data
i.e. i want to make the <p>...</p> as single line. i mean delete the carrage returns only inside <p>...</p> my following code does the job, but only for the last <p>...</p>. i don't know how to loop it here. pls suggest<input> This is to test. this is to test <p>This is to test. This is to test</p> <p>This is to test. This is to test</p> This is to test. this is to test </input> <output> This is to test. this is to test <p>This is to test. This is to test</p> <p>This is to test. This is to test</p> This is to test. this is to test </output>
Note: also please let me know how to include the source code in this page, any special tags for that? i mean the code formatting is often getting messed when i post$infile = $ARGV[0]; open(IN, '<', "temp.in") || die "\nCan't open temp.in \n"; open(OUT, '>' "temp.out"); $/=""; while(<IN>) { if($_=~s/(.*)<p>(.*)\<\/p\>(.*)//ms) { $pre = $1; $par = $2; $pos = $3; $par=~s#\n# #ig; print OUT "$pre<p>$par\<\/p\>$pos"; } } close(IN); close(OUT);
edited by ybiC: Reformatted - balanced <code> tags around sample input and code
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Efficiency issues in text parsing
by CombatSquirrel (Hermit) on Aug 25, 2003 at 08:51 UTC | |
by texuser74 (Monk) on Aug 27, 2003 at 00:44 UTC | |
by CombatSquirrel (Hermit) on Aug 27, 2003 at 01:04 UTC | |
by texuser74 (Monk) on Aug 27, 2003 at 06:25 UTC | |
by CombatSquirrel (Hermit) on Aug 27, 2003 at 09:50 UTC | |
|