Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^4: Variable number of foreach loops

by abhay180 (Acolyte)
on Nov 28, 2013 at 05:09 UTC ( #1064738=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Variable number of foreach loops
in thread Variable number of foreach loops

thanks a lot. yes i get it now. In the same light.....i want to call nfor() with different number of arguments...

nfor(1,\@a_1); nfor(2,\@a_1,\@a_2); nfor(3,\@a_1,\@a_2,\@a_3);...so on nfor(N,\@a_1,\@a_2,...\@a_N).
I have a way...but what to check if there is a much crispier way to do it.


Comment on Re^4: Variable number of foreach loops
Download Code
Re^5: Variable number of foreach loops
by BrowserUk (Pope) on Nov 28, 2013 at 05:20 UTC

    Where will you get the variable number of arrays from? And how will you be storing them?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      I have stored my data in N arrays. N varies from 1..20 I have a random string, that i breakdown into some N-segments. Each Segment is then a array. Now i want to run nfor() on these. So as you can see segment size is random. Hence variable number of arrays.

        That's not very clear. Could you post a little code to show me what you mean?

        For example, if you have code like this:

        my( @a, @b, @c ); ## stuff here to fill the arrays

        What happens if you need another array @d?


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re^5: Variable number of foreach loops
by hdb (Parson) on Nov 28, 2013 at 12:40 UTC

    If you store your arrays (more specifically references to your arrays) in an array, you can say

    my @arrayOfArrays = ( \@a_1,\@a_2,...,\@a_20 ); my $n = 10; nfor( $n, @arrayOfArrays[ 0..$n-1 ] );

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1064738]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (11)
As of 2014-09-01 20:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (17 votes), past polls