好的,所以我正在尝试制作自己的标记语言[对于一个班级,我知道它很愚蠢],但我在运行它时遇到了很多麻烦。 一旦我添加导致调用 arraySplitter 函数的文本,它似乎就卡住了(只是暂停,我假设它陷入了一个循环。)。 如果您愿意,我可以提供信息和输出。这似乎是一个简单的错误,因为我对 perl 相当陌生。
#JokeCode -> HTML
use strict;
use warnings;
use Getopt::Std;
my %opts=();
theFunctionThatActuallyParsesTheNonsense($opts{i});
my $questionCounter;
my $tempVar;
my @arrayForSplit;
my @goodArray;
my $curLine;
sub theFunctionThatActuallyParsesTheNonsense
{
my $outputF = $_[0];
$questionCounter= 0;
while (<LINES>)
{
$curLine= $_;
if($curLine =~ m/&&url/)
{
@arrayForSplit = split(/ /,$_);
$curLine =~ s/$arrayForSplit[1]//;
$curLine =~ s/$arrayForSplit[2]//;
$curLine =~ s/&&url/<a href="$arrayForSplit[1]">$arrayForSplit[2]/;
$curLine =~ s/url&&/<\/a>/;
print @arrayForSplit;
}
$curLine =~ s/\&\&b /<b>/;
$curLine =~ s/ b\&\&/<\/b>/;
$curLine =~ s/&&i /<i>/;
$curLine =~ s/ i&&/<\/i>/;
$curLine =~ s/&&u /<u>/;
$curLine =~ s/ u&&/<\/u>/;
$curLine =~ s/&&tt/<tt>/;
$curLine =~ s/tt&&/<\/tt>/;
$curLine =~ s/&&grn/<span style="color:#00ff00">/;
$curLine =~ s/grn&&/<\/span>/;
$curLine =~ s/&&red/<span style="color:#ff0000">/;
$curLine =~ s/red&&/<\/span>/;
$curLine =~ s/&&blu/<span style="color:#0000ff">/;
$curLine =~ s/blu&&/<\/span>/;
$curLine =~ s/&&ex/<pre class="code">/;
$curLine =~ s/ex&&/<\/pre>/;
if($curLine =~ m/&&tf/)
{
$curLine =~ s/&&tf/<form><br><input type="text" name="$questionCounter"><\/form>/;
$curLine =~ s/tf&&//;
$questionCounter++;
}
print "even here?";
if($curLine =~ m/&&mc/)
{
print "How bout now?";
@goodArray = arraySplitter($curLine);
foreach (@goodArray)
{
$curLine =~ s/&&mc/<input type="radio" name="$questionCounter" value="$_"> $_ <br>/;
}
$curLine =~ s/&&mc/<br>/;
$curLine =~ s/mc&&/<input type="radio" name="questionCounter" style="display: none;"\/>/;
$questionCounter++;
}
print OUT $curLine;
print OUT "\n";
}
sub arraySplitter
{
print "Are you still there?";
my @retArray;
my $arrayPlace = 0;
my @mcArray = split(/ /,$_[0]);
print @mcArray;
if(scalar(@mcArray)-1 < 1)
{
print "The size of the array is 0";
exit 1;
}
while ($arrayPlace < scalar(@mcArray)-1)
{
$retArray[$arrayPlace] = $mcArray[$arrayPlace];
}
print @retArray;
return @retArray;
}
}