Schrift
[thread]11234[/thread]

Wert aufzählen



<< >> 7 Einträge, 1 Seite
Gast Gast
 2008-02-02 11:55
#105479 #105479
Hallo,

ich habe eine Funktion für einen Chat zum umwandeln von Smileycodes:

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
sub smileys_handler
{
my($self,$main,$text) = @_;

return if $main->{current_user}{nosmileys};

if (!exists($self->{smileys}))
{
$self->{smileys} = {};
foreach my $smiley (@{$main->{settings}{smileys}})
{
my $image = undef;
foreach (@$smiley)
{
if (!defined($image))
{
$image = $_;

my ($width,$height);
($width,$height) = @{$main->{settings}{images}{$image}} if defined($main->{settings}{images}{$image});
$width = (defined($width) ? " width=$width": "");
$height = (defined($height) ? " height=$height": "");

my $alt = $main->toHTML($smiley->[1]);
$image = "<img src=\"$main->{settings}{urls}{imagesurl}$image.gif\" border=0$width$height alt=\"$alt\">";
}
elsif ($_ ne '/hidden/')
{
$self->{smileys}{$main->toHTML($_)} = $image;
}
}
}
}

$$text =~ s/([^\s<>]+)/($self->{smileys}{$1}||$1)/ge;
}


Wie kann ich die Variable $smileys aufzählen, sodass die Ausgabe von $$text nur stattfindet, wenn nicht mehr als bsp. 5 Smilies im Text vorkommen?

Der erste Versuch war:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
if(!defined($smiley_count))
{
my $smiley_count = 0;
}
else
{
$smiley_count ++;
}

return if ($smiley_count >= 7);


Das klappt nur überhaupt nicht. Weiß jemand Rat?

Danke schonmal für eure Hilfe :)
styx-cc
 2008-02-02 20:53
#105490 #105490
User since
2006-05-20
533 Artikel
BenutzerIn

user image
Ich muss gestehen, dass ich mich in deinem Code nicht zurecht finde. Grunsaetzlich sollte das so in etwa gehen:

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
sub xy {
  my $i = 0;
  for (qw/hier deine liste/) {
    #tu sonst was

    $i++;
  }
  return $i if($i < 5);
}
Pörl.
Gast Gast
 2008-02-03 12:26
#105494 #105494
Danke, jedoch funktioniert das nicht. Zumindest nicht so, wie ich es versuche:

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
40
sub smileys_handler
{
my($self,$main,$text) = @_;

return if $main->{current_user}{nosmileys};

if (!exists($self->{smileys}))
{
$self->{smileys} = {};
foreach my $smiley (@{$main->{settings}{smileys}})
{
my $image = undef;
my $i = 0;

foreach (@$smiley)
{
if (!defined($image))
{
$image = $_;
$i++;

my ($width,$height);
($width,$height) = @{$main->{settings}{images}{$image}} if defined($main->{settings}{images}{$image});
$width = (defined($width) ? " width=$width": "");
$height = (defined($height) ? " height=$height": "");

my $alt = $main->toHTML($smiley->[1]);
$image = "<img src=\"$main->{settings}{urls}{imagesurl}$image.gif\" border=0$width$height alt=\"$alt\">";
}
elsif ($_ ne '/hidden/')
{
$self->{smileys}{$main->toHTML($_)} = $image;
}
}
return $i if($i > 5);
}
}
$$text =~ s/([^\s<>]+)/($self->{smileys}{$1}||$1)/ge;

}


Wenn ich $i beispielsweise in $image ausgeben lassen will (also den aktuellen Wert $i direkt hinter dem Smiley) ist der Wert gleichbleibend 1 d.h. er wird nicht erhöht bei jedem neuen Smiley sondern immer auf gesetzt und dann wieder um 1 erhöht.
styx-cc
 2008-02-03 13:11
#105496 #105496
User since
2006-05-20
533 Artikel
BenutzerIn

user image
Das liegt an
Code (perl): (dl )
if (!defined($image))
da $image nur ein Mal nicht definiert ist, wird $i auch nur ein Mal inkrementiert.
Pörl.
Gast Gast
 2008-02-03 18:04
#105513 #105513
Das heißt? Nicht möglich oder nur was ändern?
#Kein Kommentar
 2008-02-03 18:37
#105516 #105516
User since
2007-06-09
575 Artikel
HausmeisterIn
[default_avatar]
ähm... ändern...
Gerade weil wir alle in einem Boot sitzen, sollten wir froh sein, dass nicht alle auf unserer Seite sind
Gast Gast
 2008-02-03 20:50
#105526 #105526
Die Lösung war leichter ;) Danke trotzdem!

Code: (dl )
1
2
3
4
5
6
7
8
9
my $s_count = 0;
my $spml = $main->{settings}{smileys_per_message_limit};

if ($spml < 0 || $main->hasPermission('ignore_smileys_per_message_limit')) {
$$text =~ s/([^\s<>]+)/($self->{smileys}{$1}||$1)/ge;
}
else {
$$text =~ s/([^\s<>]+)/($self->{smileys}{$1} && $s_count++<$spml ? $self->{smileys}{$1} : $1)/ge;
}
<< >> 7 Einträge, 1 Seite



View all threads created 2008-02-02 11:55.