perlでの参加者数の表示

[上に] [前に] [次に]
like 2000/06/05(月) 03:04:52
ちゃっとの参加者数の表示で、

$total=0;
foreach $line (@lines) {
($timerec,$handle,$host2,$dmy) = split(/\t/, $line);
if( $times-60 < $timerec){
$time2=$times-$timerec;$total++;
if($line eq $lines[$#lines]){
print "$handle<!--$time2-->";
}
else{
print "$handle<!--$time2-->,";
}
}
}
if($total){
print "($total)";
}else{
print "(0)";
}

とやると、
    名前,名前,名前 (3)
とゆう風に参加者数が後ろについてしまうんですけど。
    (3) 名前,名前.名前
とするにはどうしたらいいのでしょうか。

八戸にゃあ 2000/06/05(月) 07:19:17
多分、数を数えるのと表示するのを同じfor文でやってるから解らないのかな?

$total=0;
foreach $line (@lines) {
($timerec,$handle,$host2,$dmy) = split(/\t/, $line);
if( $times-60 < $timerec){
  $total++;
}
}

参加人数カウントを先にやって

if($total){
print "($total)";
}else{
print "(0)";
}
で表示。その後、名前を表示させる為に

foreach $line (@lines) {
($timerec,$handle,$host2,$dmy) = split(/\t/, $line);
if( $times-60 < $timerec){
$time2=$times-$timerec;
if($line eq $lines[$#lines]){
print "$handle<!--$time2-->";
}
else{
print "$handle<!--$time2-->,";
}
}
}

で、多分うまく行くと思います。(未確認)

andi 2000/06/05(月) 09:03:12
if($total){
print "($total)";
}else{
print "(0)";
}

って意味あるの?
最初に$total = 0;
ってあるから条件判断必要無いと思うけど。

if($line eq $lines[$#lines]){
  print "$handle<!--$time2-->";
}else{
  print "$handle<!--$time2-->,";
}

も push(@sanka,"$handle<!--$time2-->");
にして最後に

$sanka = join(',',@sanka);

とかしたほうが好み。

ところでインデントした方が良いですよ。

ぺんぎん 2000/06/06(火) 02:49:37
[[解決]]
根本的に間違ってたんですね・・・(汗)
ちゃんと表示されました。ありがとうございます。
それと、まだまだ勉強中なんでいろいろ変なとこがあるのは許して下さい。(苦笑)
(でも言われた方が勉強になりますけどね。(笑))

like 2000/06/06(火) 02:51:15
失礼。(笑)

[上に] [前に] [次に]