#!/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=)); 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);