17:17 >perl 1859_SoPW.pl
["a. answer \n", "b. answer \n", "c. answer \n"]
17:18 >
####
my $file = 'quiz4.txt';
...
open(my $fh, '<', $file)
or die "Cannot open file '$file' for reading, stopped";
...
close $fh
or die "Cannot close file '$file', stopped";
####
use strict;
use warnings;
use Data::Dump;
my %answers;
my $question;
while (my $line = )
{
if ($line =~ / ^ (\d+) \. /x)
{
$question = $1;
}
elsif ($line =~ / ^ \* (\w+) \. \s* (.*?) \s* $ /x)
{
warn "Overwriting answer for question $question"
if exists $answers{$question};
$answers{$question} = [$1, $2];
}
}
dd \%answers;
__DATA__
1. question?
*a. answer begin end
b. answer
c. answer
2. question?
a. answer
*b. answer
c. answer
3. question?
a. answer
b. answer
*c. answer
####
17:26 >perl 1859_SoPW.pl
{
1 => ["a", "answer begin end"],
2 => ["b", "answer"],
3 => ["c", "answer"],
}
17:27 >