amit hetawal wrote:
> 
> Hello all,
>   I am writing a matrix to a file as :
> 
> open(WRITE, ">training.txt");
> for ($x = 1; $x<27; ++$x)
> {
>   for($y=1; $y<27;++$y)
>   {
>   print WRITE "$matrix[$x][$y] ";
>     }
>   print WRITE "\n";
> 
> }
> 
> this code is working fine and writing the file in format as ;
> 0 0 0 0 0 0 0 1 1 1
> 2 3 4 5 0 0 0 0 0 0
> .
> .
> .
> 
> but when i want to retrieve this matrix in a new prog. and that too
> same as a matrix as above.. i am not able to get the same matrix
> again. How can i achieve this.. Any ideas.... 

First off, I assume you know that you are not writing the entire array
structure to the file since arrays in Perl start at 0, not 1.

That being said, this is how you would retrieve it back into a 1-based
array structure:

    open READ, "training.txt";
    @matrixstr = <READ>;
    close READ;

    chomp @matrixstr;
    
    @matrix = ( ' ' );  # Fill $matrix[0]
    for $line (@matrixstr)
    {
        push @matrix, [ ' ', split(' ', $line) ];
    }
    

-- 
Bowie
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to