On Thu, 2003-10-16 at 17:53, James Edward Gray II wrote: > On Thursday, October 16, 2003, at 03:25 PM, Kevin Old wrote: > > > James, is it possible to ask for a little more help with this? > > Nope, you've used up all your free answer tokens. <laughs> Oh, > alright, just this once...
Help with my script AND Comedy! Folks, don't forget to tip your waitress... <grin> > > > Here's the actual data I'm parsing (it's padded with spaces, but dont' > > worry about them) and delimited by semicolon's. > > Ah, the Real-Question-Switcheroo! ;) Yeah, sorry about that.....I've learned my lesson....from now on, the data goes in the first post. :D > Okay, first, just have to ask this question: Are we doing this in the > best way we possibly can? What about something like this? > > my @data; > my @headers = split /;/, scalar <DATAFILE>; > while (<DATAFILE>) { > chomp; > my @fields = split /;/, $_; > foreach (@fields) { s/^\s+//; s/\s+$//; } > push @data, { map { ($header[$_], $fields[$_]) } 0..$#headers }; > } > > print Dumper([EMAIL PROTECTED]); # so you can see what it makes... > Not sure I got your point. The data didn't have the look I needed. > Okay, enough with my tangent. I'll assume you know what you want and > we'll give that a go. Let's change it up a little though, to make my > life easier, which is all we really care about ;) : > > my %quads = ( quad1 => [ ], > quad2 => [ ], > quad3 => [ ], > quad4 => [ ] ); > while (<DATAFILE>) { > chomp; > my @fields = split /;/, $_; > foreach (@fields) { s/^\s+//; s/\s+$//; } > push @{ $quads{quad1} }, [ @fields[ 0..7 ] ]; > push @{ $quads{quad2} }, [ @fields[ 8..14 ] ]; > # I didn't understand the spec perfectly, so you probably need to fix > # the following push() where I mostly guessed > push @{ $quads{quad3} }, [ @fields[ 0, 8..14 ] ]; > push @{ $quads{quad4} }, [ @fields[ 15..18 ] ]; Yes, this is almost what I need, but instead of the headers being in the first column, I need the in the first row. Here's an example I put together to build the first quad. open (DATAFILE, "mthsum") or die "Can't open file $!\n"; my @tmp = (); my $i = 0; while(<DATAFILE>) { chomp; my $j = 0; my @fields = split /;/, $_; foreach (@fields) { s/^\s+//; s/\s+$//; } #push @tmp, [ @fields[0..7] ]; foreach ( @fields[ 0..7 ] ) { # any idea $tmp[$j][$i] = $_; # if there's a better $j++; # way to write this } # maybe without the $i and $j $i++; # or as a push ??? } print "$tmp[2][0]\n"; # result is STD REPL SHIPPED > } > > print Dumper(\%quads); # just to show what we have here > > # or we can keep going to get back to the array you asked for... > > my @array_2d = @{ $quads{quad1} }; > for (my $i = 0; $i < @array_2d; $i++) { > push @{ $array_2d[$i] }, undef, @{ $quads{quad2}[$i] }; > } > push @array_2d, [ ]; > push @array_2d, > map { [ @{ $quads{quad3}[$_] }, undef, @{ $quads{quad4}[$_] } ] } > 0..$#{ $quads{quad3} }; > > print Dumper([EMAIL PROTECTED]); # I believe that gets us back to where you Yes, this part is perfect. James, again I sincerely appreciate your help with this script and am once again awed by the open source community and the lengths some will go to help others, no matter how complex and confusing the situation is. Thanks so very much! Kevin -- Kevin Old <[EMAIL PROTECTED]> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]