sriordan has asked for the wisdom of the Perl Monks concerning the following question:


I am trying to extend a parsing script that writes to Excel using Spreadsheet::WriteExcel but have run into an issue trying to create worksheets mid-parse. I need to be able to create a variable name on the fly when a new type of input date is found. ie If a new type is found called DataType1043 in the input data it would lead to:

my $worksheet_1043 = $workbook->add_worksheet("1043 Data");

Being fairly new to Perl I do't really know if it's possible much less if it is sane to create a variable on the fly that way. Failing that, being able to create all the sheets from a external list after a preparse might work.

Any help will be greatly appreciated.

Thanks,

-SR

Replies are listed 'Best First'.
Re: Dynamic variable naming
by diotalevi (Canon) on Oct 06, 2004 at 23:00 UTC

    Declare a hash and save into it.

    my %worksheets; $worksheets{ '1043 Data' } = $workbook -> add_worksheet( '1043 Data' ) +;
      Guess I should have thought of that. Thanks!