Brad Cahoon wrote:
> Hi Perl Masters

Hello,

> I have a problem with a script which is suposed to open a huge text
> file and take 70 lines, create a file, then take the next 70 lines
> create a file and so on until it has parsed the whole file. My code
> just doesn't work and my brain cannot figure out while{while{}} loops
> Help please.
> 
> Thanks
> Brad
> 
> 
> Code:
> 
> #!  /usr/bin/perl
> 
> my $input = 'test12.txt';
> my $end= '.txt';
> my $fileno=1;
> my $lineno=1;
> open BIG, "test12.txt", or die "can't $!";
> 
> while (<BIG>) {
> 
> print "$lineno";
> $newfile = "$fileno$end";
> $fileno++;
> open  NEW  ,"> $newfile";
> 
> while ($lineno < 71){
> $lineno++;
> print NEW  $_;
> }}

It looks like you want something like this:

#!/usr/bin/perl
use warnings;
use strict;

my $input  = 'test12.txt';
my $end    = '.txt';
my $fileno = 1;

open BIG, '<', $input or die "can't open '$input' $!";

while ( <BIG> ) {
    print $.;
    my $newfile = $fileno++ . $end;
    open NEW, '>', $newfile or die "can't open '$newfile' $!"
        unless ( $. - 1 ) % 70;
    print NEW;
    }

__END__



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to