Looking for help please........
I am trying to produce an tabular output (multi-dimensional array) based on values derived from an XML file. The search strings work correctly BUT as 'push' appends the collected input to '@results' it gives me this:
NB:Ignore the subscripts, they arent part of the output, just trying showing the '@results'array
Present Output
--------------
[0,0] StringAttrib1
[0,1] StringAttrib2
[0,2] StringAttrib3
[0,3] StringAttrib4
[1,0] 100
[1,1] 150
[1,2] 276
[1,3] 345
[2,0] 1
[2,1] 2
[2,2] 4
[2,3] 3
BUT I want it to look like this:
NB: again subscripts are NOT part of output, just how I would like the array to look.
[0,0] StringAttrib1 [0,1] 100 [0,2] 1
[1,0] StringAttrib2 [1,1] 150 [1,2] 2
[2,0] StringAttrib3 [2,1] 276 [2,2] 4
[3,0] StringAttrib4 [3,1] 345 [3,2] 3
This isn't a quite print format problem, what I think Im trying to do is create a multidimensional array that I can then use in further scripts.
My problem is in the 'push' line I figure:
push @results, [split(' ', $1)];
Evan
I am trying to produce an tabular output (multi-dimensional array) based on values derived from an XML file. The search strings work correctly BUT as 'push' appends the collected input to '@results' it gives me this:
NB:Ignore the subscripts, they arent part of the output, just trying showing the '@results'array
Present Output
--------------
[0,0] StringAttrib1
[0,1] StringAttrib2
[0,2] StringAttrib3
[0,3] StringAttrib4
[1,0] 100
[1,1] 150
[1,2] 276
[1,3] 345
[2,0] 1
[2,1] 2
[2,2] 4
[2,3] 3
BUT I want it to look like this:
NB: again subscripts are NOT part of output, just how I would like the array to look.
[0,0] StringAttrib1 [0,1] 100 [0,2] 1
[1,0] StringAttrib2 [1,1] 150 [1,2] 2
[2,0] StringAttrib3 [2,1] 276 [2,2] 4
[3,0] StringAttrib4 [3,1] 345 [3,2] 3
Code:
open FILE, "test.xml";
while ( $line = <FILE> ) {
if( $line =~ m~<$pattern1>(.*?)</$pattern1>~m ) {
#extract values between XML tags
push @results, [split(' ', $1)];
}
if( $line =~ m~<$pattern2>(.*?)</$pattern2>~m ) {
push @results, [split(' ', $1)];
}
if( $line =~ m~<$pattern3>(.*?)</$pattern3>~m ) {
push @results, [split(' ', $1)];
}
}
for my $list_ref (@results) {
for my $item_ref (@{$list_ref}) {
print OUTFILE $item_ref,"\n";
}
print OUTFILE "\n";
}
This isn't a quite print format problem, what I think Im trying to do is create a multidimensional array that I can then use in further scripts.
My problem is in the 'push' line I figure:
push @results, [split(' ', $1)];
Evan