Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Trying to split a file up into 10 separate files. I would assume that split would work for this purpose, yet doesn't seem to do the job when I ask it to look for whole words (I'm making the script look for key words that mark the splits.) Any suggestions? I'm pretty new to Perl and maybe overlooking something obviously plain and simple :)

Replies are listed 'Best First'.
Re: ikk
by btrott (Parson) on Mar 17, 2000 at 11:01 UTC
    You should be able to use split, yes.

    If the words that split the records are just regular strings (ie., not regular expression), you could use the special $/ variable. Set it to the string, then just read in the file normally--it should read it in in chunks separated by the string. The chunks will string include the string that you used to split the input, so if you don't want it, strip the strings out.

    $/ = "----\n"; while (<DATA>) { print "{\n", $_, "}\n"; } __DATA__ foo bar ---- baz ---- quack
    Try it out--see how it works for you.

    If it doesn't, try posting some of your own code and some sample data.