Thread Unmatched [ in regex
(14 answers)
Opened by Gast at 2007-09-07 01:09
Das funktioniert bei mir ohne Probleme:
Code (perl): (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 #!/usr/bin/perl use strict; use warnings; sub readQuestion { my $FileName=shift(@_); my $CountLine=shift(@_); my $QuestionLine=''; open(QFILE,'<',$FileName) or die "Error opening \"$FileName\" ($!)\n"; $CountLine-- while($CountLine>0 && ($QuestionLine=<QFILE>)); close(QFILE); die "Not enought Lines in \"$FileName\"\n" if($CountLine>0); die "Line empty! \n" if($QuestionLine eq ''); chomp($QuestionLine); my $Separator=substr($QuestionLine,0,1,''); my @list=split(m/(?:\Q$Separator\E)+/,$QuestionLine); my $Category=shift(@list); my $Question=pop(@list); my $Answer=$list[0]; return ($Category,$Question,$Answer); } printf("C: %s \nQ: %s \nA: %s \n", readQuestion('test.txt',3)); exit(0); |