|No such thing as a small change|
returning tied arrayby strat (Canon)
|on Jan 07, 2007 at 12:40 UTC||Need Help??|
strat has asked for the
wisdom of the Perl Monks concerning the following question:
I wrote a little script called excelPerl.pl (like xlsPerl, but using Win32::OLE for getting read/write-access to the excel file) which tries to do to an excel file what perl -ane does for a text file, and to keep the interface as similar as possible, I also use the array @F for accessing the cells of one row. Since I want to save changes of elements of @F into the excel file, I decided to use a tied array.
The program works fine, but I couldn't find a clean way to return the tied array from a subroutine so I can use it as array (and not as array reference)
Here a minimal code example returning as arrayref which works:
If I just change POS1 to my @array = TieVariable(); and POS2 to return @array; to be able to work with an array in my main program, the array looses its binding, and the change in $array-> = 1000; can't be written to the excel file.
Using a global variable
If I use @F as global variable and fill it, it would work; but then I have to know the name of the global variable in the subroutine, and can only use one @F.
Working with an alias
using a package variable and working with something like: our @F; *F = \@MyPackage::Array1;, but then I have to know the variable's name in my main program, and can only use one @MyPackage::Array1
Move the tie into the main program
I like this solution best, but then in the main program you have to know you are working with a tied array
Writing a sourcefilter or similar
Working with the arrayref-solution and writing a source filter which converts accesses to $F to $F-> looks much to complicated.
Do you know another solution how I can do it?
The main program of excelPerl.pl should look something like: