how to create multiple array variable in a loop

Discussion in 'Programming' started by kalaid, Oct 23, 2008.

  1. #1
    In php code to create multiple array variable using loop and assign value will be as below

    for($i=0;$i<10;$i++)
    {
    $j=$i+1;
    $arr$j[$i]="some value";
    }
    Above code will create array variable from arr1 to arr10 and assign value.

    I want to convert same code to perl , how can i do this
     
    kalaid, Oct 23, 2008 IP
  2. salahsoftware

    salahsoftware Peon

    Messages:
    63
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I have removed the errors in the code:

    for($i=0;$i<10;$i++)
    {
    $j=$i+1;
    $arr[$j[$i]="some value";
    }

    Now, the same code should work in PERL.
     
    salahsoftware, Oct 23, 2008 IP
  3. kalaid

    kalaid Guest

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    #!D:\Perl\bin\perl
    print "Content-type: text/html\n\n";
    print "<b>Hello, world</b>";
    $data_file="E:/LogAnalyzer/exim_mainlog.22";
    open(FETs, $data_file) || die("Could not open file!");
    @raw_data=<FETs>;
    $j=0;
    foreach $val (@raw_data)
    {
    @chars = split(/ /, $val);
    for($i=0;$i<8;$i++)
    {
    $j=$i+1;

    $arr$j[$i]=$chars[$i];

    }

    }
    print @arr1;
    print @arr2;

    In the above code i cannot create multiple array name based on loop value and assign value. Please rectify issue in the above code
     
    kalaid, Oct 23, 2008 IP
  4. kalaid

    kalaid Guest

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    please help me to solve the above issue
     
    kalaid, Oct 23, 2008 IP