#! /usr/local/bin/perl # reads in one file, and splits that file into smaller files, # the split points being indicated in the input file by # "####begin filename"; e.g. if our input file name is x # and is 100 lines long, then if we insert "####begin y" # and "####begin z" before the 1st and 35th lines of x, # then running this perl script on x will produce new files # y and z, consisting of the first 34 and last 66 lines of x, # respectively # open the file specified in the first command-line argument # fails, then print the error message and exit open(INFILE,@ARGV[0]) || die "Can't open $ARGV[0]\n"; # while there are still lines left to read from the file do while () { # split the input line, $_, into the "tokens" which were # separated by spaces in the input; the tokens will be # accessible as @_[0], @_[1] etc. split; # do a vi-editor-style search of the input line for the # string "####begin", and if found, then open the # next new file; otherwise continue printing to the # current new file if (/####begin/) {open(OUTFILE,">".@_[1])} else {print OUTFILE $_}; }