#!/usr/local/bin/perl -w
#                     ^^ delete this if you only have perl4
# Extract the "EXAMPLES" part of an  R help file --
# ----         -----     Martin Maechler <maechler@stat.math.ethz.ch
$/ = "\n)"; # $INPUT_RECORD_SEPARATOR
            #-- does not work for all; eg. TITLE(..), ARG(..) are not recognized

$Pat = '^EXAMPLES\(';
$some = 0;
line:
while (<>) {
    s/^\n+//;
    ##--- At this stage, each "line" starts with "KEYWORD(" and ends with ")"
    ##--> could also extract others..

    # Show what we have now (for DEBUGGING):
    # s/\n/��/g; print STDERR "$.:\t|$_\n";

    next line unless /$Pat/; #Dbg:  print "\n\n___FOUND___ $.:\t|$_\n";
    do { $some = 1; print "\n" } unless $some;
    s/${Pat}\n//; s/\)$//;
    s/\nBLANK\s*\n/\n\n/g;
    print;
}
print "---- NO Example yet... \n" unless $some;