Given your clarifications, this change to Abigail's code may work better for you:
#!/your/perl/here
use strict;
use warnings;
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 D v4 E wwww4 F", # note change to C..D
"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", "F");
my $regex = join '\s+(\w*)\s+', @fields;
my @accounts_2 = map {[/$regex/]} @accounts;
__END__
The code map {[/$regex/]} @accounts creates an anonymous array for each element of @accounts.
And with the debugger:
DB<3> x @accounts_2
0 ARRAY(0x1ca7364)
0 'x1'
1 'y1'
2 'z1'
3 'v1'
4 'w1'
1 ARRAY(0x1ca2b30)
0 'x2'
1 'y2'
2 'zzz2'
3 'v2'
4 'w2'
2 ARRAY(0x1cbe7cc)
0 'x3'
1 'y3'
2 'z3'
3 'v3'
4 'w3'
3 ARRAY(0x1cbe88c)
0 'x4'
1 'y4'
2 '' # reflects data change above
3 'v4'
4 'wwww4'
4 ARRAY(0x1cbf97c)
0 'x5'
1 'y5'
2 'z5'
3 'v5'
4 'w5'
5 ARRAY(0x1cbe8bc)
0 'x6'
1 'y6'
2 'z6'
3 'v6'
4 ''
Note that if the stuff between field markers resembles the field markers, this won't work. Also, for pathological inputs, backtracking is a real issue.
-QM |