
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?
|