Commits

Anonymous committed 0145a92

Modernised the Perl.

  • Participants
  • Parent commits 98f124f

Comments (0)

Files changed (3)

lib/presentations/qp/perl-for-newbies/2/convert-from-old.pl

-#!/usr/bin/perl -w
+#!/usr/bin/perl
 
 use strict;
+use warnings;
 
 use File::Find;
 

lib/presentations/qp/perl-for-newbies/3/convert-from-old.pl

-#!/usr/bin/perl -w
+#!/usr/bin/perl
 
 use strict;
+use warnings;
 
 use File::Find;
 
     }
 }
 
+sub _slurp
+{
+    my $filename = shift;
+
+    open my $in, "<", $filename
+        or die "Cannot open '$filename' for slurping - $!";
+
+    local $/;
+    my $contents = <$in>;
+
+    close($in);
+
+    return $contents;
+}
+
 foreach my $filename (@files)
 {
-    open I, "<$filename";
-    open O, ">$filename.wml";
+    my $text = _slurp($filename);
+
+    open my $out, ">", "$filename.wml"
+        or die "Could not open '$filename.wml' - $!";
     
-    print O "#include 'template.wml'\n\n";
-    my $text = join("", <I>);
+    print {$out} "#include 'template.wml'\n\n";
 
     $text =~ s/<!--+ *& *begin_footer *-->.*?<!--+ *& *end_footer *--+>//s;
     $text =~ s/<!--+ *& *begin_header *-->.*?<!--+ *& *end_header *--+>//s;
     $text =~ s/<!--+ *& *begin_contents *-->.*?<!--+ *& *end_contents *--+>/<qpcontents \/>/gs;
     $text =~ s/<!--+ *& *begin_menupath *-->(.*?)<!--+ *& *end_menupath *--+>/<menupath>$1<\/menupath>/gs;
     
-    print O $text;
-    close(I);
-    close(O);
-    
+    print {$out} $text;
+
+    close($out);
 }

lib/presentations/qp/perl-for-newbies/4/src/exceptions/die-eval.pl

     }
 }
 
-&perform_transaction();
+perform_transaction();