G'day Geert,

++ You're asking good questions. :-)

You've received a lot of good answers, so I won't delve into those again. However, I did want to say something about abstraction.

Whenever you have code with many lines that are almost identical, consider abstracting that code into one or more subroutines. Here's an example:

my @inputpaths = @{test_paths([1..3])}; push @inputpaths, @{test_paths([4..7])}; sub test_paths { my ($ids) = @_; state $prefix = 'C:/Temp/xml/'; return [ map "${prefix}test${_}.xml", @$ids ]; }

That code is intended to give you an idea of abstraction based on what you originally posted.

In other scenarios, you might want to pass $prefix as an argument to give you more flexibility; and, unless all your filenames look like testN.xml, you'd probably want to do something different than passing a list of numbers (to replace N). I'd also recommend you heed the advice of ++haukex regarding the use of modules such as File::Spec.

— Ken


In reply to Re: Adding items to arrays: best approach? by kcott
in thread Adding items to arrays: best approach? by geertvc

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.