Kyle Sexton
unread,Feb 3, 2012, 10:48:43 PM2/3/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Kansas City Ruby User Group
All,
I'm struggling with a hopefully simple problem in one of my programs.
Given an block of text that can be any length in size:
str =<<EOF
ebdcgfa
eadbcfg
dcbeagf
fecdbga
gfabecd
egabcdf
agdfebc
bdcegfa
abgcdef
ceagdfb
egbfdca
dbcgfea
EOF
I'd like to have the output be:
str1 = "1 ebdcgfa 2 eadbcfg 3 dcbeagf 4 fecdbga"
str2 = "5 gfabecd 6 egabcdf 7 agdfebc 8 bdcegfa"
str3 = "9 abgcdef 10 ceagdfb 11 egbfdca 12 dbcgfea"
Each new string variable will have a chunk of four links from the
input block, prefaced with the line number of the block. I don't need
str1, str2, str3 to be string type if some other type works better,
just a way to reference them in order. Input block size can range
from 0 to some large number, say 100000. What's a clean way to do
this? I considered dumping all of the original block into an array,
but I'm not sure if arrays are designed for manipulating that many
elements.
I feel like I'm missing something and this is probably easier than my
loops with counting iterators, but maybe not. :)
Thanks,
Kyle Sexton