Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
... I am not sure what I need to do to get around these. ... I need them to be global variables, so I define them outside of the WHILE loops. If you say that you see them as redundant can you tell me how to get around doing this?

Please understand that what I see as redundant is useless explicit initialization of a variable. In the case of
    my $input_file = undef;
the assignment does exactly what is done by default; it is purely redundant.

Semantically erroneous statements like
    my @files = undef;
are redundant in the present circumstances because the very next thing you do with these arrays (as far as I can see) is to assign them valid data, thus undoing the erroneous initialization. In other circumstances, the erroneous initialization may lead to a nasty bug.

... I need them to be global variables, so I define them outside of the WHILE loops.

Of course, you need to define lexical variables where you need to use them. On this note, you only use the  @dt lexical within the scope of the  if($firstline==1){ ... } statement block, so that's exactly where I would define it:

if($firstline==1){ ... my @dt = $header[0] =~ /(\d+)/g; ... } else { <IN> for 1..1 }
(Incidentally, the  <IN> for 1..1 statement is needlessly involved: if you just want to read and discard one line, the simple  <IN>; statement does the trick.)


Give a man a fish:  <%-{-{-{-<


In reply to Re^3: What can I do to improve my code - I'm a beginner by AnomalousMonk
in thread What can I do to improve my code - I'm a beginner by Anonymous Monk

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    [1nickt]: marto all good after the hurricane?

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (7)
    As of 2017-10-17 10:21 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My fridge is mostly full of:

















      Results (225 votes). Check out past polls.

      Notices?