Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Do you know where your variables are?

Comment on


I am lost in how to "variablize" this.

Working code:

use strict; use Spreadsheet::WriteExcel; my $workbook = Spreadsheet::WriteExcel->new("demo.xls"); my $worksheet_BOB = $workbook->add_worksheet('BOB'); my $worksheet_SUE = $workbook->add_worksheet('SUE'); $worksheet_BOB->write('A2', "Bob is here"); $worksheet_SUE->write('A2', "Sue is here"); __END__

What I want do do is make the _BOB a variable and loop through and array to build the worksheets. and then be able to reference the writes with the variable names.Below may not be syntactically correct but functional what I want to do

use strict; use Spreadsheet::WriteExcel; my $workbook = Spreadsheet::WriteExcel->new("demo.xls"); my @PEOPLE = ("BOB" , "SUE", "JOHN" ); foreach (@PEOPLE) { my $worksheet_$_ = $workbook->add_worksheet('$_'); } $NAME = "BOB" $worksheet_$NAME->write('A2', "$NAME is here"); $NAME= "SUE" $worksheet_$NAME->write('A2', "$NAME is here"); __END__

In reply to variable in variables by ohgary

and:  <code> code here </code>

  • Please read these before you post! —
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (11)
    As of 2014-03-17 17:13 GMT
    Find Nodes?
      Voting Booth?

      Have you used a cryptocurrency?

      Results (355 votes), past polls