(
[ # data matching first condition
[ $first, $second, $third ], [ $first, $second, $third ], ...,
],
[ # data matching second condition
[ $first, $second, $third ], [ $first, $second, $third ], ...,
],
)
####
#!/usr/bin/env perl -l
use strict;
use warnings;
my @print_data;
for (sort ) {
chomp;
my ($first, $second, $third) = split /,/;
next if $second ne $third;
push @{$print_data[$first ne $second]}, [ $first, $second, $third ];
}
{
print '*** Simple Formatting Rules ***';
my @rules = (
"%s (1st) equals %s (2nd) and %2\$s (2nd) equals %s (3rd)\n",
"%s (1st) doesn't equal %s (2nd) but %2\$s (2nd) does equal %s (3rd)\n",
);
for my $i (0 .. 1) {
printf $rules[$i], @$_ for @{$print_data[$i]};
}
}
{
print '*** More Complex Formatting Rules ***';
my @rules = (
[
"%s (3rd) equals both %s (1st) and %s (2nd)\n", [ 2, 0, 1 ],
],
[
"%s (3rd) only equals %s (2nd)\n", [ 2, 1 ],
],
);
for my $i (0 .. 1) {
printf $rules[$i][0], @{$_}[@{$rules[$i][1]}] for @{$print_data[$i]};
}
}
__DATA__
2,2,3
2,2,2
2,1,1
1,2,3
1,2,2
1,1,1
####
*** Simple Formatting Rules ***
1 (1st) equals 1 (2nd) and 1 (2nd) equals 1 (3rd)
2 (1st) equals 2 (2nd) and 2 (2nd) equals 2 (3rd)
1 (1st) doesn't equal 2 (2nd) but 2 (2nd) does equal 2 (3rd)
2 (1st) doesn't equal 1 (2nd) but 1 (2nd) does equal 1 (3rd)
*** More Complex Formatting Rules ***
1 (3rd) equals both 1 (1st) and 1 (2nd)
2 (3rd) equals both 2 (1st) and 2 (2nd)
2 (3rd) only equals 2 (2nd)
1 (3rd) only equals 1 (2nd)