in reply to Parsing Exercise set
#!/usr/bin/perl use strict; undef $/; my $s = <DATA>; my @questions; while( $s =~ s! (?:\\begin{instructions}(.*?)\\end{instructions}\s*)? \\begin{exer}\s* \\begin{exertext}(.*?)\\end{exertext}\s* \\begin{soln}(.*?)\\end{soln}\s* (?:\\begin{answer}(.*?)\\end{answer}\s*)? \\end{exer} !!sx ){ push @questions, { instructions => $1, exertext => $2, soln => $3, answer => $4, }; } use Data::Dumper; print Data::Dumper::Dumper \@questions; __DATA__ #### place the sample input here ####
|
|---|