Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Builing a object name with for loop

by devbond (Novice)
on Aug 30, 2013 at 13:59 UTC ( #1051634=perlquestion: print w/ replies, xml ) Need Help??
devbond has asked for the wisdom of the Perl Monks concerning the following question:

my $workbook = Spreadsheet::WriteExcel->new('perl.xls'); $s1 = $workbook->add_worksheet('cpze1'); $s2 = $workbook->add_worksheet('cpze2'); $s3 = $workbook->add_worksheet('cpze3'); $s4 = $workbook->add_worksheet('cpze4'); $s5 = $workbook->add_worksheet('cpze5'); $s6 = $workbook->add_worksheet('cpze6'); $s7 = $workbook->add_worksheet('cpze7'); $s8 = $workbook->add_worksheet('cpze8'); for ($i=1;$i<=8;$i++) { for ($r=0;$r<=24;$r++) { for ($c=0;$c<=4;$c++) { $s{$i}->write($r,$c,$arrays[$i][$r][$c]); } } }
I want to write values in all worksheets ,s1,s2,s3 ...s8 using a for loop the above code fails at $s{$i}.../I am not able to create object name with for loop variables. Please help

Comment on Builing a object name with for loop
Download Code
Re: Builing a object name with for loop
by Corion (Pope) on Aug 30, 2013 at 14:01 UTC
Re: Builing a object name with for loop
by hdb (Prior) on Aug 30, 2013 at 14:10 UTC

    If you use an array, things become much easier:

    my @s; $s[$_] = $workbook->add_worksheet( "cpze".$_ ) for 1..8; # $s[0] remains undefined! for my $i (1..8) { for my $r (0..24) { for my $c (0..4) { $s[$i]->write($r,$c,$arrays[$i][$r][$c]); } } }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1051634]
Approved by hdb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (14)
As of 2014-09-18 13:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (115 votes), past polls