Hi,
I am using perl v5.24.1
I have to run the code recursively for a set of 4 values, multiple times. Each time the set of 4 values will be different but I'll know these before running the program

So what I have done is created a text file and use it as input file for the program.
The filename is stored in a variable in program and that variable is used each time input file needs to be accessed. I add the list of input values in this input file in space separated format. So the input file looks like:

contents of input.txt:
text1 string1 word1 number1
text2 string2 word2 number2
text3 string3 word3 number3
text4 string4 word4 number4

In code I am reading this input.txt one line at a time, spliting that line on space as delimiter ad storing each value in variable. Then run the program for these list of variables. So my program runs as many times as the number of lines in the input.txt

It is working fine but I have few questions:
Q-1) Is this approach fine or is there any better way to do it?
Q-2) Will it be better to embed the data in input.txt in the code itself rather than keeping it in a separate file?
Q-3) If YES to question 2 then what data structure should I use that is easy to edit in future as well as easy to loop over?

open (my $fh, '<', $input_file) or die "Can't read from '$input_file': + $!"; while (<$fh>) { my ($var1, $var2, $var3, $var4) = split (' ', $_); #Call to subroutine1 (by passing $var1, $var2, $var3, $var4) which + calls subroutine2, which calls subroutine3. }

In reply to What is better: Static input data in separate file or embedding static input data in code. by Perl300

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.