Permalink
Browse files

no need to write to disk just use IO::Scalar

  • Loading branch information...
schelcj committed Oct 1, 2012
1 parent a2636ef commit f22efc5899fed282e5f404e1bb66bb7ec550d670
Showing with 10 additions and 17 deletions.
  1. +7 −11 create.pl
  2. +3 −6 parse.pl
View
@@ -4,7 +4,7 @@
use WWW::Mechanize;
use Net::Netrc;
use Readonly;
-use File::Slurp;
+use File::Slurp qw(read_file);
use File::Temp;
use IO::Scalar;
use Data::Dumper;
@@ -18,13 +18,12 @@
Readonly::Scalar my $DIRECTIONS => q{Hello World};
Readonly::Scalar my $SUMMARY => q{Goodbye World};
-my $latex = $ARGV[0]; # TODO - use getopts
-my $lesson_name = q{2013}; # TODO - get from command line arg
-my $title = q{SPH Algebra Assesment for 2013}; # TODO - get from command line arg
-my $agent = get_login_agent();
+my $latex = $ARGV[0]; # TODO - use getopts
+my $lesson_name = q{2013}; # TODO - get from command line arg
+my $title = q{SPH Algebra Assesment for 2013}; # TODO - get from command line arg
+my $agent = get_login_agent();
my $question_ref = parse_latex($latex);
-
print Dumper $question_ref;
exit;
@@ -41,13 +40,10 @@ sub parse_latex {
$contents =~ s/^(?:(.*)?\\begin{document})|(?:\\end{document})$//gs;
- write_file($temp_fh->filename, $contents);
-
{
local $/ = q{%QUESTION };
- foreach my $line (read_file($temp_fh)) {
- push @questions, $line;
- }
+ my $content_fh = IO::Scalar->new(\$contents);
+ @questions = map {$_} $content_fh->getlines;
}
foreach my $question (@questions) {
View
@@ -1,7 +1,7 @@
#!/usr/bin/env perl
use Modern::Perl;
-use File::Slurp;
+use File::Slurp qw(read_file);
use File::Temp;
use IO::Scalar;
use Data::Dumper;
@@ -14,13 +14,10 @@
$contents =~ s/^(?:(.*)?\\begin{document})|(?:\\end{document})$//gs;
-write_file($temp_fh->filename, $contents);
-
{
local $/ = q{%QUESTION };
- foreach my $line (read_file($temp_fh)) {
- push @questions, $line;
- }
+ my $content_fh = IO::Scalar->new(\$contents);
+ @questions = map {$_} $content_fh->getlines;
}
foreach my $question (@questions) {

0 comments on commit f22efc5

Please sign in to comment.