I added a couple of debug lines and it looks like it is reading past the end
of the array. It seems like I forget to add something to say last if(
$array_pos == $MAX );

Thanks for the insight!

-J-e-s-s-

-----Original Message-----
From: John W. Krahn [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 03, 2002 5:33 PM
To: [EMAIL PROTECTED]
Subject: Re: Use of unitialized value error.


Jess Balint wrote:
> 
> Hello, I have been getting an error in my code for a reason that I cannot
> understand. The code looks like this:
> 
> -----snip-----
> 
> $\ = ":";
> foreach( @random_numbers ) { print; }
> 
> open( INFILE, $opt_i ) or die( "Cannot open $opt_i: $!" );
> open( OUTFILE, "> $opt_o" ) or die( "Cannot open $opt_o: $!" );
> 
> my( $file_pos ) = 0;
> my( $array_pos ) = 0;
> while( <INFILE> ) {
>         $file_pos++;
>         my( $x ) = $random_numbers[$array_pos];
>         my( $y ) = $file_pos;
>         if( $y == $x ) {
>                 $array_pos++;
>                 print OUTFILE $_;
>         }
> }
> 
> -----snap-----
> 
> The errors are as follows. I know the random_numbers array is filled
because
> the code prints out the whole array. The x and y variables were stuck in
> there to see if it would work. It originally said if(
> $random_numbers[$array_pos] == $file_pos ) but that wouldn't work either.
> Any ideas? Thanks. P.S. This is perl version 5.005_03
> 
> Use of uninitialized value at /qmds/jbalint/20020128/datsample.pl line 47,
> <INFILE> chunk 478985.
                 ^^^^^^

> Use of uninitialized value at /qmds/jbalint/20020128/datsample.pl line 47,
> <INFILE> chunk 478986.
> Use of uninitialized value at /qmds/jbalint/20020128/datsample.pl line 47,
> <INFILE> chunk 478987.

How many elements does @random_numbers have?  It looks like you are
trying to read past the end of the array.


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to