in reply to Re: Looking for a good way to split a file into equal sized arrays
in thread Looking for a good way to split a file into equal sized arrays

Thanks for all the suggestions, folks. While that flip flop did work out as anticipated, it turns out thats not exactly what I thought I needed
What I ended up doing was sending all the data in the file to an array then incrementing the elements of that array in a for loop. Inside that for loop, I set a few triggers via a switch. Since the beginning value of each line tells me what sort of data it contains, I then split each line depending on what it was:
{{{vars}}} my $infile = <STDIN>; print"Your input file is $infile\n\n"; open (INFILE, "<$infile")||die "no such file"; while (<INFILE>) { @data = <INFILE>; for ($x = 0; $x<=$#data; $x++){ chomp ($data[$x]); switch ($data[$x]){ # If start of section, increment array by 3 to skip header # case /^Begin Targets/ { $x += 3; } case /^0 / { # do not want last; } case /^1 / { @line = split(/ /,$data[$x]); # Get data out last; } case /^2 / { @line = split(/ /,$data[$x]); # Get data out last; } case /^3 / { @line = split(/ /,$data[$x]); # Get data out last; } # end case3 } # end switch } # end for } #end
In each case I can take the line and set it to some variable depending on which place in the field I want,
$DistX[$x] = $line[2]; $DistY[$x] = $line[3];
...etc
Well Im half way there, Now I just need to output this data to a csv spreadsheet to plot it...but thats for tomorrow :)