Split a Latex Beamer file by frame

Sometimes, when a presentation is getting too big for a file, I try to split the frames on several files, usually one file per slide. Being tired of doing this by hand, I’ve written a Perl script for doing that:

#!/usr/bin/perl -w
# Split a beamer file into several files, with one slide on each
#           Ruymán Reyes Castro
use strict;
use warnings;
use utf8;
my $slide_num = 0;
my $ACTUAL;
my $inside = 0;
while  (<>;) {
 if ( /begin{frame}/ ) {
   # new file begins
   $slide_num++;
 } elsif (/frametitle{(.*)}/) {
    $inside = 1;
   # Extract file name
   my $filename = filenamize($1);
   print "Writing: ".$slide_num."_".$filename." \n";
   # create file
   open ACTUAL, ">;", "R".$slide_num."_".$filename.".tex" or die $1;
   print ACTUAL "\\begin{frame} \n";
   print ACTUAL $_;
 } elsif ( /end{frame}/ ) {
    print ACTUAL $_;
    # End file
    print "Done. \n";
    close ACTUAL;
    $inside = 0;
 } else {
    # Write to file
    print ACTUAL $_ if ($inside) ;
 }
}

Filenamize translates the frame title to a string suitable for naming a file

sub filenamize {
   use Encode;
   my $in = Encode::decode('utf-8', shift);
   $in =~ tr/ /_/;
   $in =~ tr/áéíóúñ/aeioun/;
   $in =~ tr/:/_/;
   return $in;
}

It’s only a quick-solution, but maybe it’s useful for someone over there…