big problem with arrays... 
Author Message
 big problem with arrays...

Hi all!

I would like to get some values of Excel-Sheet per row
here is one part of the script

<snip>
my $_new_excel = new Spreadsheet::ParseExcel; my ($iR, $iC);
my $_new_excel_wb = $_new_excel->Parse($_);

$_new_excel_ws = $_new_excel_wb->{Worksheet}[Timesheet];

for ( my $iR=4; $iR<=29; $iR++) {
for ( my $iC=23; $iC<=26; $iC++) {
 $_new_excel_cell = $_new_excel_ws->{Cell}[$iR][$iC]
 $_new_excel_value = $_new_excel_cell->Value
  foreach ($_new_excel_value) {

   }
  }
 }

Quote:
}

</snap>

The script should take row 4-29 and get the values of field 23-26

dynamic that means the array should name like "ARRAY_ROW_NUMBER" and
so on. So that I know the arrays name are the row.I think that
in this script he delete the arrays every time in the second loop.
so how can made this that push every new element in the same array
for one row. But the main thing is how can i made this that the
arrayname is "dynamic"

Oh its terrible to explain such difficult things in a forgein
language but i hope you know what i mean.

Erik



Mon, 17 May 2004 19:46:15 GMT  
 big problem with arrays...

(snip)

Quote:
> for one row. But the main thing is how can i made this that the
> arrayname is "dynamic"

> Oh its terrible to explain such difficult things in a forgein
> language but i hope you know what i mean.

(snip)

Not sure if I do...

But if you want to run the code several times, and each time push

prototype--

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

use Data::Dumper;







        # or with the Spreadsheet module:

    }

Quote:
}

# placeholder for the spreadsheet
my $xls = {};
for my $row (1..30) {
    $xls->{Cells}[$row] = [
        map { "$row:$_" } 'a'..'z'
    ];

Quote:
}






#------

Hope this helps-
Steve



Mon, 17 May 2004 23:52:05 GMT  
 big problem with arrays...
On Thu, 29 Nov 2001 19:46:15 +0100,

Quote:
> Hi all!

> I would like to get some values of Excel-Sheet per row
> here is one part of the script

><snip>
> my $_new_excel = new Spreadsheet::ParseExcel; my ($iR, $iC);

The second statement is useless here. You're scoping the $iR and $iC
variables in the for loop anyway.

Quote:
> my $_new_excel_wb = $_new_excel->Parse($_);

> $_new_excel_ws = $_new_excel_wb->{Worksheet}[Timesheet];

You should use strict, so you don't accidentally forget to declare
variables. It's safer, and makes your programs easier to debug, or at
least, it prevents hard to find bugs.

Quote:
> for ( my $iR=4; $iR<=29; $iR++) {
> for ( my $iC=23; $iC<=26; $iC++) {
>  $_new_excel_cell = $_new_excel_ws->{Cell}[$iR][$iC]
>  $_new_excel_value = $_new_excel_cell->Value

Neither of the two lines above has a terminating semicolon. Syntax
error.

Quote:
>   foreach ($_new_excel_value) {

This loop is useless. You loop over one element only.

Quote:

>    }
>   }
>  }
> }

Too many closing braces.

Please, next time you post code, make sure it at least is
syntactically valid...

Quote:
> The script should take row 4-29 and get the values of field 23-26

> dynamic that means the array should name like "ARRAY_ROW_NUMBER" and
> so on. So that I know the arrays name are the row.I think that

It is possible to do that, but you don't really want to do it. What
you want to do is use symbolic references, and it's generally
considered to be a bad and dangerous, or at least difficult to debug
and hard to maintain strategy.

I suggest you move to using real references, and a more complex data
structure. You should probably read the perldata, perlref, perllol and
perldsc documentation for more information. Something like (untested,
and with changed variable names):

my $excel = Spreadsheet::ParseExcel->new();
my $excel_wb = $excel->Parse($_);
my $excel_ws = $excel_wb->{Worksheet}[Timesheet];


for my $iR (4 .. 29)
{

        for my $iC (23 .. 26)
        {

        }


Quote:
}


each row, in order, and each row array will contain the cells, in
order.

As said: Read perlref, perllol and perldsc for more information.

Martien
--
                                |
Martien Verbruggen              |
Trading Post Australia Pty Ltd  | What's another word for Thesaurus?
                                |



Tue, 18 May 2004 00:13:49 GMT  
 big problem with arrays...

Quote:

> Hi all!

> I would like to get some values of Excel-Sheet per row
> here is one part of the script

> <snip>
> my $_new_excel = new Spreadsheet::ParseExcel; my ($iR, $iC);
> my $_new_excel_wb = $_new_excel->Parse($_);

> $_new_excel_ws = $_new_excel_wb->{Worksheet}[Timesheet];

> for ( my $iR=4; $iR<=29; $iR++) {
> for ( my $iC=23; $iC<=26; $iC++) {
>  $_new_excel_cell = $_new_excel_ws->{Cell}[$iR][$iC]
>  $_new_excel_value = $_new_excel_cell->Value
>   foreach ($_new_excel_value) {

>    }
>   }
>  }
> }

> </snap>

> The script should take row 4-29 and get the values of field 23-26

> dynamic that means the array should name like "ARRAY_ROW_NUMBER" and
> so on. So that I know the arrays name are the row.I think that
> in this script he delete the arrays every time in the second loop.
> so how can made this that push every new element in the same array
> for one row. But the main thing is how can i made this that the
> arrayname is "dynamic"

> Oh its terrible to explain such difficult things in a forgein
> language but i hope you know what i mean.

> Erik

Uh, variable name can contain letters, numbers, and underscores, but
they can only begin with a letter or number:
$_pepsi = "good"; #won't work! :(
$pepsi = "good"; #will work! :)

$_new_excel should be $new_excel
got it?



Tue, 18 May 2004 02:48:06 GMT  
 big problem with arrays...

(snipped)

Quote:
> Uh, variable name can contain letters, numbers, and underscores, but
> they can only begin with a letter or number:
> $_pepsi = "good"; #won't work! :(
> $pepsi = "good"; #will work! :)

> $_new_excel should be $new_excel
> got it?

Where did you get that idea?

%  perl -lwe 'my $_pepsi = "yummy sugar+water"; print $_pepsi;'
yummy sugar+water

--
Steven Kuo
http://www-sss.nsc.com/~skuo/



Tue, 18 May 2004 03:24:34 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. A big associative array - How big is it!

2. Big problem with associative arrays on disk.

3. Big problem with associative arrays on disk.

4. big import big mess!!!!

5. Convertaing BIG BIG integers to HEX

6. Randal's Big Day in Big D

7. How big is big?

8. Very big array

9. newbie: will a big array hurt performance?

10. sort an array and print out biggest number

11. very big array

12. How to avoid reading big file into array ?

 

 
Powered by phpBB® Forum Software