[Gllug] Perl Problem
Martin A. Brooks
martin at hinterlands.org
Thu Feb 1 00:17:18 UTC 2007
Brad Cahoon wrote:
> Hi Guys and Gals,
>
> I have sent this to perl beginners group but they seem to all be
> asleep and I am not, can anyone help?
>
> Thanks
> Brad
>
>
>
> Hi Perl Masters
>
> 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 $_;
> }}
Do you see the part where where you reset $lineno? No, me either.
I especially like the part where you set a scalar to the name of the
file, and then never bother to actually use it.
Also add "use strict;" and "use warnings;" near the top.
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list