Indented text converted to arrays of arrays
From: Brad Baxter (bmb_at_ginger.libs.uga.edu)
Date: 06/29/04
- Next message: Anno Siegel: "Re: error logs..."
- Previous message: Michele Dondi: "Re: Totally stuck"
- Next in thread: Tore Aursand: "Re: Indented text converted to arrays of arrays"
- Reply: Tore Aursand: "Re: Indented text converted to arrays of arrays"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 29 Jun 2004 17:37:50 -0400
Greetings,
I would like to take a table of indented text like the following:
AAA
BBB
CCC
DDD
EEE
FFF
GGG
... and convert it into a nested array of arrays like the following:
[
[ 'AAA' => [
'BBB',
'CCC',
] ],
[ 'DDD' => [
[ 'EEE' => [
'FFF',
] ],
] ],
'GGG',
]
That is, if an element $a is an array ref, then $a->[0] is the text for
that level and $a->[1] is an array ref to the next level(s). Otherwise $a
is the text for that level.
The indenting is regular, the levels may be arbitrarily deep, and no
double indenting is allowed, i.e., the following is disallowed:
AAA
BBB
CCC
DDD
The solution I've come up with so far is to create the following literal
string and eval it:
[
[ 'AAA' => [
[ 'BBB' => [
] ],
[ 'CCC' => [
] ],
] ],
[ 'DDD' => [
[ 'EEE' => [
[ 'FFF' => [
] ],
] ],
] ],
[ 'GGG' => [
] ],
]
This obviously is not exactly what I describe above, but I can make it
work. However, this solution seems rather draconian, and I feel certain
there is a much simpler answer.
Regards,
Brad
- Next message: Anno Siegel: "Re: error logs..."
- Previous message: Michele Dondi: "Re: Totally stuck"
- Next in thread: Tore Aursand: "Re: Indented text converted to arrays of arrays"
- Reply: Tore Aursand: "Re: Indented text converted to arrays of arrays"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|