gayu_justin has asked for the wisdom of the Perl Monks concerning the following question:

My requirement is, i want to map some checklist values to some groups. following is my code @selectbox1 => contains the selected select groups @selectbox2 => contains selected checklist

foreach $select1(@selectbox1){ my $sql_select1 = "select id from group_management where group_name = +'$select1'"; my $box1 = $dbslave -> prepare($sql_select1); $box1 -> execute(); while($select_box1= $box1->fetchrow_array()) { push (@box1,$select_box1); } my $box_1 = @box1;// currently i tried like this to store the current +value .NEED CORRECTION HERE foreach $select2(@selectbox2) { my $sql_select2 = "select id from checklist where checklist_name = '$s +elect2'"; my $box2 = $dbslave -> prepare($sql_select2); $box2 -> execute(); while($select_box2 = $box2->fetchrow_array()) { push (@box2,$select_box2); } my $box_2 = @box2;// currently i tried like this to store the current +value .NEED CORRECTION HERE my $sql_insert = "insert into checklist_group_mapping values ('',$box_ +2,$box_1)"; my $ins = $dbslave -> prepare($sql_insert); $ins -> execute(); } }
how can i assign the current value of the array to a varible?so that i can insert it into mapping table
  • Comment on want to store the current value of the array ina variable inside for loop
  • Download Code

Replies are listed 'Best First'.
Re: want to store the current value of the array ina variable inside for loop
by rjt (Curate) on Jul 06, 2013 at 12:06 UTC

    Please post your actual Perl code, and

    use warnings; use strict;

    Preferably, a minimal example that illustrates the problem you are having. With things // comments, $box_1 vs $box1, it's hard to tell what your exact intent was, or which other errors may be masking the real problem.

    how can i assign the current value of the array to a varible?so that i can insert it into mapping table

    Given your code, my guess is that you want the last value (in this case, the last one pushed in the loop above) in @box1 to be assigned to $box_1. Is that correct? If so, you can do so like this:

    my $box_1 = $box1[-1];

    If that's not it, please clarify what you need, ideally with a concise example.

      Thank you....issue fixed.my requirement was this :

       my $box_1 = $box1[-1];

      :)

Re: want to store the current value of the array ina variable inside for loop
by Anonymous Monk on Jul 06, 2013 at 12:09 UTC

    Dont you simply mean?

     @copybox1 = @box1;

    Thats what it looks like.