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?

Hi,

Its because you're not Coping with Scoping and your subroutines do not accept arguments and have unclear purpose

using empty prototype

sub UE_Log is declared inside a while loop

sub Beam_Hystersis is declared inside while loop

Try to pass arguments while disabling prototype checking  &Beam_Hystersis($filename); but sub Beam_Hystersis accepts no arguments (also has no prototype, but most subs should have no prototype)

Download Modern Perl , it explains the same stuff as Coping with Scoping and perlintro, and try writing like this

Each time you add a new subroutine create a new file moresubs1184355-001.pl

#!/usr/bin/perl -- use strict; use warnings; use Getopt::Long qw/ GetOptions /; use Data::Dump qw/ dd /; Main( @ARGV ); exit( 0 ); sub Main { my %opts; GetOptions( \%opts, 'carriers|c|C=s', 'num_tp|t|T|TP=i', 'Help|h|H', 'bs|b|B|BS|bs', 'version|v|V', 'legend|l|L=s', 'altitude|a|A=i', 'actdir|d|D=s', ); dd( \%opts ); } __END__ $ perl moresubs1184355-001.pl -c=1 -t=2 -v=3 -h=4 -l=5 -a=6 -d=7 Option v does not take an argument Option h does not take an argument { actdir => 7, altitude => 6, carriers => 1, legend => 5, num_tp => 2 +}

Next is moresubs1184355-002.pl

#!/usr/bin/perl -- use strict; use warnings; use Getopt::Long qw/ GetOptions /; use Data::Dump qw/ dd /; Main( @ARGV ); exit( 0 ); sub Main { my %opts; GetOptions( \%opts, 'carriers|c|C=s', 'num_tp|t|T|TP=i', 'Help|h|H', 'bs|b|B|BS|bs', 'version|v|V', 'legend|l|L=s', 'altitude|a|A=i', 'actdir|d|D=s', ); dd( \%opts ); WorkTheWorkbook( \%opts ); } sub WorkTheWorkbook { my( $optsRef ) = @_; dd( $optsRef ); print "altitude=$optsRef->{altitude}\n"; use autodie qw/ open close /; open my($fh), '<', '$optsRef->{altitude}'; # fake return; } __END__ $ perl moresubs1184355-002.pl -c=1 -t=2 -v=3 -h=4 -l=5 -a=6 -d=7 Option v does not take an argument Option h does not take an argument { actdir => 7, altitude => 6, carriers => 1, legend => 5, num_tp => 2 +} { actdir => 7, altitude => 6, carriers => 1, legend => 5, num_tp => 2 +} altitude=6 Can't open '$optsRef->{altitude}' for reading: 'Invalid argument' at m +oresubs1184355-002.pl line 29

See how it runs? See how one you pass a variable between subroutines? How autodie dies for you when open cant open a file?

I can't help you with the next part, as the purpose of UE_Log and Beam_Hystersis is a mystery to me

But you would probably write

Beam_Hystersis( $workbook, $filename, $optsRef ); ... sub Beam_Hystersis { my( $workbook, $filename , $optsRef ) = @_; use autodie; ## stick this next to use strict so you dont have to +keep repeating open my($fh), '<', $filename; ...; $worksheet->write( ... ); ...; }

See how you pass args between subs?


In reply to Re: Can't write to the 2nd created excel workbook upon changing directory (Excel::Writer::XLSX) by Anonymous Monk
in thread 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.