in reply to How do I split a file by lines into smaller files
There are more idiomatic ways to do that, but it'll get you started.open(INFILE, $filename) or die "Can't open $filename: $!"; my @lines = <INFILE>; my @chapters; $chapters[1] = @lines[0 .. 55]; $chapters[2] = @lines[56 .. 112];
Update: merlyn's right. That's what happens when you switch approaches while typing out your code. If you don't want to use references, do instead:
In general, I'd discourage that approach, because appending numbers to variable names is a warning sign. In this case, it's not a big deal.@chapter1 = @lines[0 .. 55]; @chapter2 = @lines[56 .. 112];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How do I split a file by lines into smaller files
by merlyn (Sage) on Mar 06, 2001 at 06:48 UTC | |
|
Re: Re: How do I split a file by lines into smaller files
by BrotherAde (Pilgrim) on Mar 06, 2001 at 06:36 UTC |