hi to all monks!

i have problem, this has been going on for a week already. just want to know what should i do. i still a newbie in perl.. uhmm.. just want to ask if how should i make my foreach loop dynamic.. the array found on the foreach loop basically gets values from the txt file.and prints all possible combinations based from the options in the text file. the problem is that how do i change my code if another option would be placed on the txt file.. the code and the txt file are placed below.

TXT FILE (testcase) option1:apple,banana,orange option2:apple,banana,orange option3:pork,chicken,beef #location and name of txtfile my $testcase="/home/jay/testcase/" my @a= &getValues($testcase,"option1"); my @b= &getValues($testcase,"option2"); my @c= &getValues($testcase,"option3"); foreach $ao(@a) { foreach $bo(@b) { foreach $co(@c) { print "$ao$bo$co; } } } sub getValues() { # accept parameter local ($keyword) = $_[1]; local ($mytestcases) = $_[0]; # retrieve txtfile testcases rows open (TESTCASE, $mytestcases) || die "couldn't open the file!\n"; @raw_value = <TESTCASE>; close(TESTCASE); # locate keyword foreach $rowsxx (@raw_value) { # split row item to get keyword @row_values = split(":",$rowsxx); #print "@row_values[0]\n"; # checking of keyword [use eq to compare string] if ($keyword eq @row_values[0]) { # split @row_values[1] to get config values @config_values = split(",",@row_values[1]); return @config_values; last; } } }

if another option would be placed for example

option4;salt,sugar,vinegar
how do i change my code so that it would be dynamic in the sense that no matter how many options i place in my txt file it will all be evaluated.what i did in my foreach loop was basically a static one..basically i want the code to be dynamic so that any in the future if there are options to be added the user would just place values on the txt file without changing the code.. hope you can help me with this.. thanks in advance..


In reply to how to make a foreach loop dynamic? by jaydot

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.