On Thu, 2003-10-16 at 11:52, James Edward Gray II wrote:
> On Thursday, October 16, 2003, at 09:16 AM, Kevin Old wrote:
>
> > James,
> >
> > On Wed, 2003-10-15 at 22:42, James Edward Gray II wrote:
> >
> >> Now, if you meant a boring two-dimensional table, that's MUCH easier
> >> and more sane.
> >>
> >> my @array_2d = ( [ 1.. 4, undef, 5..8 ],
> >> [ 'A'..'D', undef, 'E'..'H' ],
> >> [ ],
> >> [ 9, 10, undef, 11, 12 ],
> >> [ 'I', 'J', undef, 'K', 'L' ] );
> >>
> >> If it's neither of those, try me again. I'm dumb, but I won't give
> >> up.
> >> ;)
> >
> > Yes, this is what I'm trying to get for a result. I'm dumb too, that's
> > why I'm formatting data this way.
> >
> > What needed to happen was that the data be broken down and displayed
> > into quadrants out of the two-dimensional array. I say needed because
> > the data feed I get has been reformatted so I don't have to worry about
> > that anymore.
> >
> > I would however be interested in knowing how to get my previous array
> > into the @array_2d above.
>
> That's a tricky question for me to answer. I can think of a lot of
> ways to change it, but I'm not sure I understand the pattern you were
> using. If I had divided 12 items equally into quadrants it would have
> been three per quad. I might have done that like:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> use Data::Dumper;
>
> my @AoA = ( [ 1..12 ], [ 'A'..'L' ] );
>
> print Dumper([EMAIL PROTECTED]);
>
> # figure out where to break them up
> my $quad_count = @{$AoA[0]} / 4;
> $quad_count++ if $quad_count =~ s/\.\d+$//; # round up
>
> my @array_2d = ( [ ], [ ], [ ], [ ], [ ] );
> # walk the old rows index by index moving them to the new array
> # in the right spot
> for my $old_row ( 0, 1 ) {
> for my $index ( 0 .. $#{$AoA[0]} ) {
> my $new_row = $index < 2 * $quad_count ? $old_row : $old_row + 3;
> if ( $index < 2 * $quad_count ) {
> $array_2d[ $new_row ][ $index ] = $AoA[ $old_row ][ $index ];
> }
> else {
> $array_2d[ $new_row ][ $index - 2 * $quad_count ] =
> $AoA[ $old_row ][ $index ];
> }
> }
> }
> # add undefs to break up the quads
> splice @{ $array_2d[ $_ ] }, $quad_count, 0, undef foreach 0, 1, 3, 4;
>
> print Dumper([EMAIL PROTECTED]);
>
> __END__
>
James, is it possible to ask for a little more help with this?
Here's the actual data I'm parsing (it's padded with spaces, but dont'
worry about them) and delimited by semicolon's.
DATE;WM REPL SHIPPED;STD REPL SHIPPED;PROMO SHIPPED;ROLLOUT
SHIPPED;OTHER SHIPPED;M/I SHIPPED;TOTAL SHIPPED;WM REPL OPEN;STD REPL
OPEN;PROMO OPEN;ROLLOUT OPEN;OTHER OPEN;M/I OPEN;TOTAL OPEN;LATE
ORDERS;DUMMY ORDERS;DELETED ORDERS;HELD ORDERS
; ; ; ; ;
; ; ; ; ;
; ; ; ; ;
; ; ;
20031002; 5764; 114978; 2288; ;
39; ; 123069; ; ;
; ; ; ; ;
; ; ;
20031003; 55523; 54923; 1105840; ;
157597; 3220; 1377103; ; ;
; ; ; ; ;
; ; ;
20031006; 64457; 152142; 771045; ;
46; 1319; 989009; ; ;
; ; ; ; ;
; ; ;
20031007; 17841; 49993; 190107; ;
28778; 6971; 293690; ; ;
; ; ; ; ;
; ; ;
20031008; 12347; 103861; 1323307; ;
; 9899; 1449414; ; ;
; ; ; ; ;
; ; ;
20031009; 95842; 165819; 977485; ;
3882; 9865; 1252893; ; ;
; ; ; ; ;
; ; ;
20031010; 14384; 131304; 756744; ;
18476; 2152; 923060; ; ;
; ; ; ; ;
; ; ;
20031011; 109672; 132782; 89539; ;
11900; 3834; 347727; ; ;
; ; ; ; ;
; ; ;
20031012; 53112; 118962; 86163; ;
; ; 258237; ; ;
; ; ; ; ;
; ; ;
20031013; 55604; 50646; ; ;
; ; 106250; ; ;
; ; ; ; ;
; ; ;
20031014; 88531; 102857; 529651; ;
; 5782; 726821; 582234; 863117;
9196512; ; 87790; 64738; 10794391;
3740624; 50400; ;
There are 19 columns and what I need is:
The first 8 column in quadrant 1
The next 7 columns in quadrant 2
The Date column (from Q1, 1st column) again, plus the next 7 columns all
in quadrant 3
The last 4 columns in quadrant 4
Now, the example above splits the 2D array by 4, placing 4 columns in
each quadrant, but I can't figure out the math logic to alter it for my
needs above.
Any additional help you can offer would be absolutely awesome and would
almost require me to send a keg ;).
Thanks,
--
Kevin Old <[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]