AllPaoTeam has asked for the wisdom of the Perl Monks concerning the following question:

I found some code how to split an array into multiple arrays with the same length and splitting the array into even and odd array. I can't find one to split them into multiple uneven arrays. For example for the 1st array, I want the 7th word thru the 15th word in the line. For the 2nd array, I want the 16th word thru the 25th word in the line and so on. Any help would be greatly appreciated.

my $file_state = "C:\\Scripts\\TEMP_BY_STATE.csv"; #Open files to exact to each state open FILE, "<", $file_state or die $!; while ($in = <FILE>) { #Splits string into array @fields = split(/,/, $in); @data1 = $fields[6..15]; @data2 = $fields[16..25]; @data3 = $fields[26..55]; @data4 = $fields[56..60]; # and so on }

Replies are listed 'Best First'.
Re: Split array into multiple uneven arrays
by choroba (Cardinal) on Sep 04, 2014 at 18:16 UTC
    To create a slice, you have to change the sigil, as you would use the plural form in English:
    @data1 = @fields[6 .. 15]; # ^ # | # Here # etc.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Thank you!!!! splice does the trick!!
        I know it's probably just a typo, but be careful not to confuse Slices and splice, that's a different (if related) beast.