Hi,
Du solltest bei sowas immer ein if-else machen, das ganze geht ja schön kurz mit dem ?: Operator:
my $lastdate = ($headdata =~ /<lastdate>(.+?)</lastdate>/)
? $1 : '';
Ich habe es auf diese Weise versucht (mit : 0 statt : '', aber auch mit : '') , aber wo die Variablen leer sind, bekomme ich trotzdem die Fehlermeldung im Errorlog. Habe es so gelöst:
my $lastmessby = 0;
my $lastdate = 0;
while ($headdata =~ /<lastmessby>(.+?)</lastmessby>/) {
if ($1 ne '') {
$lastmessby = $1;
}
}
while ($headdata =~ /<lastdate>(.+?)</lastdate>/) {
if ($1 ne '') {
$lastdate = $1;
}
}
if ($lastmessby == 0 || $lastdate == 0) {
print "<tr><td class="topiclinks"><a href="$baseurl?action=showreplies&posting=$_">$thema</a></td><td class="topic"> $firstmessby </td><td class="topic"> 1 </td><td class="topic"> 2 </td><td> </td></tr>\n";
} else {
print "<tr><td class="topiclinks"><a href="$baseurl?action=showreplies&posting=$_">$thema</a></td><td class="topic"> $firstmessby </td><td class="topic"> 1 </td><td class="topic"> 2 </td><td class="topic"><span class="replyname">$lastmessby</span><br> $lastdate </td></tr>\n";
}
}
So bekomme ich auf keinen Fall eine Fehlermeldung, aber geht das vielleicht noch kürzer ?
$xNeTworKx.