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__
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|