#!c:/perl/bin/perl.exe -w use Modern::Perl; use YAML::XS; use Data::Dumper; use Text::TabularDisplay; use Text::Fold; # Note: use YAML::XS not YAML to appropriately handle # multiline blocks. Do this in Windows: # 'perl -MCPAN -e shell' # then 'install YAML::XS' # ** This won't be available from the PPM GUI in Windows ** my $yml; { local $/ = undef; $yml = ; } my (@arr) = Load($yml); my $table = Text::TabularDisplay->new(qw(ID Description By Date)); my $count; sub add_to_table { my ($desc, $area, $resp, $by) = @_; $count++; # count defined outside sub and captured by closure (my $s = fold_text("$area: $desc", 62, { soft_hyphen_threshold => 10 })) =~ s/^\s+//mg; my @row = ($count, $s, $resp, $by); $table->add(@row); # table defined outside and captured by closure } # map called in void context with the express purpose of invoking # the handy side-effect of the add_to_table sub which appends # each record as row into the tabular display referenced by # the $table var map { add_to_table($_->{description}, $_->{area}, $_->{responsible}, $_->{by} ) } sort { $a->{area} <=> $b->{area} || $a->{responsible} cmp $b->{responsible} } @arr; say $table->render; __DATA__ --- description: Mickey was asked by Minie to attend UAT at Western Controls on the 17/08 area: 1200 responsible: Mickey by: 17/08 --- description: Mickey indicated that he experienced problems with some labels for Area 1210 and requested that the inspection of the labels for areas 1210 and 1128 be postponed to Wednesday area: 1210 responsible: Mickey by: 19/08 ...