in reply to seperating blocks of file content in an array
This next one creates an array of hashrefs with keys "header" and "text" to store the data.use strict; my $i = 0; my $j = 0; my @result; while(<DATA>) { chomp; $result[(++$i % 2) ? $j++ : $j - 1] .= $_; } __DATA__ >text 4 'As the low pressure moves in, the winds should slacken towards the en +d of the day. Will be a smaller day than Tuesday, but the odd clean w +ave should be found at some spots.' >text 8 'Unsure as to what the winds will do more today as it'll depend a lot +on the track of the low pressure.' >text 9 'It'll be near calm and mellow conditions, although there's a chance o +f perhaps the odd kneehigh set wave for the North coast.'
use strict; my @data = <DATA>; my @result; chomp foreach @data; for (my $i = 0; $i <= $#data; $i += 2) { push(@result, {header => $data[$i], text => $data[$i + 1]}); } __DATA__ >text 4 'As the low pressure moves in, the winds should slacken towards the en +d of the day. Will be a smaller day than Tuesday, but the odd clean w +ave should be found at some spots.' >text 8 'Unsure as to what the winds will do more today as it'll depend a lot +on the track of the low pressure.' >text 9 'It'll be near calm and mellow conditions, although there's a chance o +f perhaps the odd kneehigh set wave for the North coast.'
|
|---|