Revision: 40304
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 29, 2011 09:02 by alfirth
Initial Code
#!/usr/bin/perl
use strict;
use warnings;
die "usage $0 <input> <output>\n" unless ($ARGV[0] && $ARGV[1]);
my $input = shift;
my $output = shift;
open (INPUT, '<', $input) or die "$input could not be opened for reading$!\n";
open (OUTPUT, '>', $output) or die "$output could not be opened for writing$!\n";
my %products;
while (<INPUT>) {
#initialize a hash of arrays keyed by product, with an array of all filenames for that product
if (m/ (\w*?)_.*sql/) {
my $product = $1;
if (m/ (${product}_02.*?sql)$/) {
$products{$product} = [] unless defined $products{$product};
push ( @{ $products{$product} }, $1 );
}
}
}
#print the largest element of the array for each product
foreach (values %products) {
local $\ = "\n";
print OUTPUT (sort( @{$_ } ))[-1];
}
Initial URL
Initial Description
Initial Title
chomp text files and return regex matches by product
Initial Tags
text
Initial Language
Perl