in reply to Array in Array
#!/usr/bin/perl use strict; use warnings; use YAML; my @accounts = ("A x1 B y1 C z1 D v1 E w1 F", "A x2 B y2 C zzz2 D v2 E w2 F", "A x3 B y3 C z3 D v3 E w3 F", "A x4 B y4 C z4 D v4 E wwww4 F", "A x5 B y5 C z5 D v5 E w5 F", "A x6 B y6 C z6 D v6 E F"); my @fields = ("A", "B", "C", "D", "E"); no warnings 'misc'; my @accounts_2 = map {[@{{split}}{@fields}]} @accounts; print Dump \@accounts_2; __END__ --- #YAML:1.0 - - x1 - y1 - z1 - v1 - w1 - - x2 - y2 - zzz2 - v2 - w2 - - x3 - y3 - z3 - v3 - w3 - - x4 - y4 - z4 - v4 - wwww4 - - x5 - y5 - z5 - v5 - w5 - - x6 - y6 - z6 - v6 - F
Short explaination of the map line: Take each element of @accounts, split it on white space, make an anonymous hash out of the results, and take a hash slice of that, indexed on @fields. Create an anonymous array of the result of the slice.
Abigail
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Array in Array
by nylon (Acolyte) on Oct 06, 2003 at 13:16 UTC | |
by CombatSquirrel (Hermit) on Oct 06, 2003 at 14:40 UTC | |
by Abigail-II (Bishop) on Oct 06, 2003 at 13:21 UTC | |
by nylon (Acolyte) on Oct 07, 2003 at 06:06 UTC | |
by Abigail-II (Bishop) on Oct 07, 2003 at 09:01 UTC |