Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: How to store multiples lines/records in a array

by Perlseeker_1 (Acolyte)
on Jul 02, 2013 at 14:35 UTC ( #1042026=note: print w/ replies, xml ) Need Help??


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


Comment on Re^2: How to store multiples lines/records in a array
Select or Download Code
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 (Abbot) 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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2014-12-25 23:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (163 votes), past polls