Hello Everyone,

I have a question regarding creating a new workbook within the same script using a loop which takes the new log file directory input from the user.

I'm using the 'Excel::Writer::XLSX' module, the first time the script runs I am able to get a good output .xlsx file with all data being populated in all created sheets, however, the second time the script runs, it is able to create the new workbook and worksheets for the new 'log file', however, the sheets are empty with no data populated. Is there any reason for that?

Here is what the main parts of the script look like:

my $workbook; my $skip_counter=0; my %opts = ('c|C|carriers=s', \$Carrier_Option, 't|T|TP=i', \$Nr_of_TP +, 'h|H|Help', \$printHelp, 'b|B|BS|bs|Bs', \$is_BS, 'v|V|Version', \$ +version, 'l|L|legend=s', \$my_legend, 'a|A|altitude=i', \$BS_RadioHei +ght, 'd|D=s', \$actdir); GetOptions(%opts); # dd \%opts; sub Change_Directory() { if($actdir eq "") { $actdir=$CWD; } else { chdir("$actdir"); } } while(1) { sub UE_Log() { $workbook = Excel::Writer::XLSX->new("$modified_filename2.xlsx") +; my $worksheet = $workbook->add_worksheet('Summary_Report'); my $worksheet2 = $workbook->add_worksheet('KPIs_Overall'); my $worksheet3 = $workbook->add_worksheet('KPIs_Per_Carrier'); my $worksheet4 = $workbook->add_worksheet('KPIs_Overall_CDF'); my $worksheet5 = $workbook->add_worksheet('KPIs_Per_Carrier_CDF'); my $worksheet6 = $workbook->add_worksheet('BRSRP_CDF'); my $worksheet7 = $workbook->add_worksheet('Rank_Overall'); my $worksheet8 = $workbook->add_worksheet('MCS_Overall'); my $worksheet9 = $workbook->add_worksheet('BRSRP_CDF_TP1'); #BW my $worksheet11 = $workbook->add_worksheet('SINR_Per_Rank'); my $worksheet10 = $workbook->add_worksheet('Distance_Plots'); . . . if ($filename=glob('*L2UE_Beam_hist.csv')) { &Beam_Hystersis($filename); } sub Beam_Hystersis { my @timestamp; my @Beam_Probability; my $All_Beam_Sum=0; my @beamIndex; my $previous_beamprobability; . . open ($fh, "<", $filename) or die("\n---ERROR: File $filename +could not be found---\n\n"); $worksheet->write(0,0,"BeamIndex#",$format); $worksheet->write(0,1,"Beam_Probability_TP0",$format); . . .} } $workbook->close(); print "To process another log file, enter the path to the log file +, or enter 'x' to exit: "; print color 'reset'; chomp(my $new_options = <>); GetOptionsFromString($new_options, %opts); dd \%opts; &Change_Directory($actdir); if($new_options eq "x") { last; } }

The following are also some of the error/warning messages i'm getting when running the script the 2nd time:

Processing File '20161206_02_1TP1RUnew_shortDriveParking_' ... Use of uninitialized value $1 in string eq at /usr/lib/perl5/site_perl +/5.14/Excel/Writer/XLSX/Utility.pm line 94. Use of uninitialized value $3 in string eq at /usr/lib/perl5/site_perl +/5.14/Excel/Writer/XLSX/Utility.pm line 96. Use of uninitialized value $col in split at /usr/lib/perl5/site_perl/5 +.14/Excel/Writer/XLSX/Utility.pm line 101. Use of uninitialized value $1 in string eq at /usr/lib/perl5/site_perl +/5.14/Excel/Writer/XLSX/Utility.pm line 94. Use of uninitialized value $3 in string eq at /usr/lib/perl5/site_perl +/5.14/Excel/Writer/XLSX/Utility.pm line 96. Use of uninitialized value $col in split at /usr/lib/perl5/site_perl/5 +.14/Excel/Writer/XLSX/Utility.pm line 101. Use of uninitialized value $1 in string eq at /usr/lib/perl5/site_perl +/5.14/Excel/Writer/XLSX/Utility.pm line 94. Use of uninitialized value $3 in string eq at /usr/lib/perl5/site_perl +/5.14/Excel/Writer/XLSX/Utility.pm line 96. Use of uninitialized value $col in split at /usr/lib/perl5/site_perl/5 +.14/Excel/Writer/XLSX/Utility.pm line 101. Use of uninitialized value $1 in string eq at /usr/lib/perl5/site_perl +/5.14/Excel/Writer/XLSX/Utility.pm line 94. Use of uninitialized value $3 in string eq at /usr/lib/perl5/site_perl +/5.14/Excel/Writer/XLSX/Utility.pm line 96. Use of uninitialized value $col in split at /usr/lib/perl5/site_perl/5 +.14/Excel/Writer/XLSX/Utility.pm line 101.

Is there any reason why I'm not getting a good output the 2nd time I run the script as part of the while loop?

Any help and guidance in this regards would be greatly appreciated...!

Thank You


In reply to Can't write to the 2nd created excel workbook upon changing directory (Excel::Writer::XLSX) by m_jaser

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.