in reply to split a file into number of file based on line count

If you are on Unix, just use the split command line utility. If you must have a perl solution, simply decide on base of the line counter $. which file to write to.

Oh, and please put your code examples inside <code>...</code> tags, that way it'll be readable. (Did you use the preview page?)

Replies are listed 'Best First'.
Re^2: split a file into number of file based on line count
by Utilitarian (Vicar) on May 13, 2009 at 09:06 UTC
    more specifically, to split into 5 ~equal files you can use the following construction in bash
    split -l$(expr $(expr $(wc -l filename |cut -d\ -f1) / 5) + 1) filena +me
      Why do all that when you can equally well use
      split -n 100 some_file
      ??

      See man split... (on some *NIXes, -l is used instead of -n to specify the line count)

      Update:

      Qualified the usage of the line count option

      A user level that continues to overstate my experience :-))
        Not general. See OP's ref to counting lines.
      That sounds like it can be golfed.
      split -l$((`cat filename|wc -l`/5+1)) filename