RE: mehr perl woes
- From
- Thomas Groß <thomas@...>
- Date
On Tue, 2004-05-11 at 13:49, Johannes Walch wrote:
> > In perl würde ich dafür die grep funktion verwenden. Die
> > macht zwar auch
> > eine Schleife ist aber um vieles schneller wie wenn man die
> > Schleife con
> > hand in perl programmiert.
>
> Dachte ich mir auch schon, aber wie geht das dann, insbesondere in einer if
> Anweisung :
Hier ein kleines Beispiel. Sollte als Ausgabe
>found
>not found
machen. Wichtig ist das \Q\E sonst würde der z.B. Suchtstring "..."
matchen.
#!/usr/bin/perl -w
@list = qw(foo bar baz);
$suche = "bar";
if (grep(/^\Q$suche\E$/, @list)) {
print "found\n";
} else {
print "not found\n";
}
$suche = "nop";
if (grep(/^\Q$suche\E$/, @list)) {
print "found\n";
} else {
print "not found\n";
}
Thread
Follow-ups:
- RE: mehr perl woes Thomas Groß <thomas@...>