nylon has asked for the wisdom of the Perl Monks concerning the following question:
I'm a perl newbie (and I know it) that's why I seek wisdom here.
The following problem came up:
I have an array with in each array-element some data that is divided by the same words. The ("border")words are always present but the lenght and content between the words differ. I need to filter the data between the ("border")words and put them in there own array-elements.
eg:
The result should be something as:#!/usr/bin/perl @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"); @fields = ("A", "B", "C", "D", "E"); @fields_plus = ("B", "C", "D", "E", "A"); $end = $#accounts + 1; $end_1 = $#fields + 1; $i = 0; $j =0; $teller = 1; foreach $jump(@accounts) { foreach $test(@fields) { $accounts_2[$j][$i] =~ (/$test(.*?)$fields_plus[$i] /sgm) ; push @accounts_2, ("$teller", "***"); $teller++ ; $i++; if ($fields[$i] == $end_2) {last} } $j++; } for ($j = 0, $j > $end, $j++) { for ($i =0, $i > $end_1, $i++) { print ("$accounts_2[$j][$i]"); } }
I got some spooky stuff. Thanks in advance for helping me :-) Nylon$accounts_2[0][0] = x1 $accounts_2[0][1] = y2 $accounts_2[][] = ... $accounts_2[1][0] = x2 $accounts_2[][] = ... $accounts_2[3][4] = wwww4 $accounts_2[][] = ...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Array in Array
by Abigail-II (Bishop) on Oct 06, 2003 at 12:37 UTC | |
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 | |
Re: Array in Array
by Zaxo (Archbishop) on Oct 06, 2003 at 15:24 UTC | |
by nylon (Acolyte) on Oct 07, 2003 at 06:01 UTC | |
by nylon (Acolyte) on Oct 07, 2003 at 06:11 UTC | |
by QM (Parson) on Oct 07, 2003 at 17:51 UTC | |
by nylon (Acolyte) on Oct 07, 2003 at 08:56 UTC | |
by Anonymous Monk on Oct 07, 2003 at 11:18 UTC | |
Re: Array in Array
by kesterkester (Hermit) on Oct 06, 2003 at 14:31 UTC |
Back to
Seekers of Perl Wisdom