Andre_br has asked for the wisdom of the Perl Monks concerning the following question:
I´ve been unable to solve this one, and I hope you can help me out with this message:
Variable "$prev_col" will not stay shared at C:\Site\cgi-bin\import.cgi line 543. Thu Jan 27 17:37:58 2005 import.cgi: Variable "$prev_row" will not stay shared at C:\Site\cgi-bin\import.cgi line 543.
Here´s the code:
This is a sub that parses excel files, and it´s within a script that handles the importation of a table into a mysql db. I´ve read the possible solution about this, regarding anonymous subs, but I still fail to have the Perl wisdom to implement this solution. Can you guys code it up for me?... if ( $extension ne "txt" && $extension eq "xls") { my $infile = "../$infile"; my $outfile = "../$outfile"; # Requesting extra modules: use Spreadsheet::ParseExcel; use Data::Dumper; # Openning the file dump open (DUMP, ">$outfile") || warn "Error opening file: $!\n"; select DUMP; # Excel parsing my $parse_excel = new Spreadsheet::ParseExcel(CellHandler => \&cell +_handler, NotSetCell => 1); my $prev_index = -1; my $prev_row = 0; my $prev_col = 0; my $workbook = $parse_excel->Parse("$infile"); # Define our own cell handler to reduce S::PE's memory use. # This function will be called each time a cell is encountered. # However, it will ignore blank cells so we have to keep track # of our location in the worksheet so that we can pad out blank # cells and rows. # sub cell_handler { my $workbook = $_[0]; my $sheet_index = $_[1]; my $row = $_[2]; my $col = $_[3]; my $cell = $_[4]; # Only process the first worksheet if ($sheet_index > 0) { $workbook->ParseAbort(1); return; } # Reset the col counter between rows $prev_col = 0 if $row != $prev_row; # Add tabs between fields and newlines between rows. Also pa +d # any missing rows or columns. # print "\n" for $prev_row +1 .. $row; print "\t" for $prev_col +1 .. $col; # Print the UNformatted value of the cell print $cell->{Val}; # Keep track of where we are $prev_row = $row; $prev_col = $col; } close DUMP; select STDOUT; }
Thanks a lot
André
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl complaining about vars not staying shared
by Tanktalus (Canon) on Jan 27, 2005 at 20:02 UTC | |
by dave_the_m (Monsignor) on Jan 27, 2005 at 23:33 UTC | |
|
Re: Perl complaining about vars not staying shared
by holli (Abbot) on Jan 27, 2005 at 20:10 UTC | |
|
Re: Perl complaining about vars not staying shared
by Fang (Pilgrim) on Jan 27, 2005 at 21:55 UTC | |
by Andre_br (Pilgrim) on Jan 30, 2005 at 04:34 UTC |