http://www.perlmonks.org?node_id=1042026


in reply to Re: How to store multiples lines/records in a array
in thread How to store multiples lines/records in a array

Hi Monks,

Thanks for the replies, its working when the length of record is 5

code suggested by experts

# HTML ignores the "\n", but it looks nicer in 'print'; $table="<table>\n"; for my $i(0..5) { $table .= "<tr>"; for (@values[$i*6 .. ($i*6+5)]) { # 'Array Slice' $table .= "<td>$_</td>"; } $table .= "</tr>\n"; } $table .= "</table>\n"

output displayed in table

ABC_TEK 12 DFE_YJK 24 JKL_GHY 26 HJK_YHJ 46 LKJ_UYH 29 GHK_YTH 23 GHS_JSF 34 GHJ_YJK 56 FHK_THE 25 SHJ_TRE 26 HSJ_TEH 39 SGH_YHK 66 AHJ_EGH 56 SGH_HEJ 42 HGE_THE 46 YHJ_JKL 44 HEJ_EJJ 67 JLE_EJK 89 EHJ_EJK 78 GSH_THK 43 EHJ_IKL 68 EHJ_EJK 57 EJH_EKL 69 HGJ_HJK 44

but if the size of the record increased from 5 to 6, i hope i need to change the logic from $i(0..6) and for (@values$i*7 .. ($i*7+6)), is thier any way where we can fetch each line based on line size

<code> for my $i(0..$#line) <code>

please give suggestion on this

Replies are listed 'Best First'.
Re^3: How to store multiples lines/records in a array (variable)
by Anonymous Monk on Jul 02, 2013 at 14:44 UTC

    is thier any way where we can fetch each line based on line size

    Sure, a)determine line size (some kind of number) b) store size in a variable (some kind of number) c) use variable instead of hard coded number ( 5 or 6)

Re^3: How to store multiples lines/records in a array
by Anonymous Monk on Jul 02, 2013 at 14:47 UTC
    Learn how the code you were given works. Past answers to you explain debugging and learning programming.
Re^3: How to store multiples lines/records in a array
by NetWallah (Canon) on Jul 03, 2013 at 03:08 UTC
    scalar (@values) will give you the number of elements in @values.

    Since you are printing 6 per line, the number of lines will be:

    my $linecount = int((scalar(@values) +5)/ 6); #Rounding up.
    use ($linecount -1) instead of the hard coded 5.

    You subtract one because the starting value is 0.

                 My goal ... to kill off the slow brain cells that are holding me back from synergizing my knowledge of vertically integrated mobile platforms in local cloud-based content management system datafication.