Thread Text Parsen (3 answers)
Opened by sid burn at 2007-04-26 16:22

bloonix
 2007-04-26 19:05
#76246 #76246
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
Sorry... klappt vielleicht nicht so supi, aber zumindest bei diesem Beispiel:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use strict;
use warnings;

my $add  = 0;
my $text = do { local $/, <DATA> };

for my $line (split /\n/, $text) {
  print $line;
  if ($line =~ m@<\s*/\s*t[dh]@) {
     $add = 0;
  } elsif ($line =~ m@<\s*t[dh]@) {
     $add = 1;
  }
  print $add ? '<br>' : "\n";
}

__END__
<html>
<head>
  <title>test</title>
</head>
<body>
<table>
  <tr>
     <th>header1</th>
     <th>header2
foo bar
foobar
</th>
  </tr>
  <tr>
     <td>column1
foo bar
foobar
</td>
     <td>column2</td>
  </tr>
</table>
</html>


Output:

<html>
<head>
<title>test</title>
</head>
<body>
<table>
<tr>
<th>header1</th>
<th>header2<br>foo bar<br>foobar<br></th>
</tr>
<tr>
<td>column1<br>foo bar<br>foobar<br></td>
<td>column2</td>
</tr>
</table>
</html>
\n\n

<!--EDIT|opi|1177600043-->
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.

View full thread Text Parsen