I'm slow again. This reads DATA (once), one line at a time, to populate '@movie'. Subroutine 'sum()' adds arrays of numbers. Otherwise, not much different from others.
#!/usr/bin/perl -w
use strict;
my @movie;
my $seen = 0;
my $collected;
while (<DATA>){
if (my ($film,$show) = /^\*.+Movie="(.+)"\s*show=(\w+)/){
push (@{$movie[$seen-1]},$collected) if $collected;
$movie[$seen++] = [($film,$show)];
$collected = 0;
}
else{
my @take = grep { $_ >= 20} split /\s/;
$collected = sum($collected,@take);
}
}
push (@{$movie[$seen-1]},$collected) or die $!;
print "Movie\tShow\tSumCollection>20\n";
print "$_->[0]\t$_->[1]\t$_->[2]\n" for @movie;
# use Data::Dumper;
# print "\n\@movie Array looks like this: \n";
# print Dumper(\@movie);
sub sum
{
my $x;
for (@_){
$x += $_;
}
return $x;
}
__DATA__
* Movie="ABC" show=4
10 20 30 14 90 30
21 13 11 10 09 23
22 05 22 15 19 20
* Movie="XYZ" show=4
10 20 30 14 90 30
21 13 11 10 09 23
22 05 22 15 19 10
FWIW
(changed some details after posting).
mkmcconn