#! perl -w ## simple script to slurp all the examples out of the text ## version of the OCaml manual, currently located at ## http://caml.inria.fr/distrib/ocaml-3.11/ocaml-3.11-refman.txt . my $contents; { local $/ = undef; $contents = ; } # there's little more OCaml after this chapter, but there are some # makefiles, C programs etc that confuse this simple script. So just # cut off at this point. $contents =~ s!Chapter 13 Dependency generator \(ocamldep\).*!!s; # get just the parts between << and >> $contents =~ s!.*?<<(.*?)>>! $1--reset--\n!gs; #print $contents; my $inml = ''; for my $line (split '\n', $contents) { if ($line =~ m,^ *#!,) { # ignore shell script shebang next; } if ($line =~ s!^ *#!!) { $inml = 1; print $line, "\n"; } elsif ($inml) { # matches very few, but there are a couple of word-wrap # problems. I don't /think/ it should be significant ... print $line, "\n"; } if ($inml and $line =~ m!;;!) { $inml = ''; print "\n"; } # make sure we clear $inml between sections, just in case if ($line =~ m!--reset--!) { $inml = ''; } }