From: dms Date: Wed, 3 Jan 2001 13:37:00 +0000 (+0000) Subject: - Finally added proper recursive SARs X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=7a4105a8c06ec5a143415f483142856d8e9abe53;p=infobot.git - Finally added proper recursive SARs git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@220 c11ca15a-4712-0410-83d8-924469b57eb5 --- diff --git a/src/Factoids/Reply.pl b/src/Factoids/Reply.pl index d0607c1..0ad9ecc 100644 --- a/src/Factoids/Reply.pl +++ b/src/Factoids/Reply.pl @@ -86,9 +86,32 @@ sub getReply { $done = 0; # EG: (blah1|blah2|blah3|) => blah1 - while ($result =~ /\((.*?\|.*?)\)/) { + while ($result =~ /\((.*\|.*?)\)/) { my $str = $1; - my @rand = split /\|/, $str; + my @rand; + + if ($done == 1) { + &status("Cool. recursive SAR factoids rock :-)"); + } + + my $x = ""; + foreach (split /\|/, $str) { + $x = $x.$_; + + if (/^\(/ or ($x ne $_ and !/\)$/)) { # start or mid. + $x = $x."|"; +### print "start or mid. ($x)\n"; + } elsif (/\)$/) { # end. +### print "end; pushing '$x$_', (was $x)\n"; + push(@rand,$x); + $x = ""; + } else { +### print "nice append. '$_'\n"; + push(@rand,$_); + $x = ""; + } + } + my $rand = $rand[rand @rand]; &status("Reply.pl: SARing '($str)' to '$rand'.");