!#/usr/bin/perl use strict; use CommonOutput; use TestParsers; ( @ARGV == 1 and -d $ARGV[0] ) or die "Usage: $0 pathname\n pathname : directory containing files to process\n"; chdir $ARGV[0] or die "chdir $ARGV[0] failed: $!\n"; # let's suppose that TestParsers can tell which parsing # function is needed based on the path (because the path # identifies both the source and the type of content): my $parser = TestParsers->new( $ARGV[0] ); my $emitter = CommonOutput->new(); for my $infile ( <*.txt> ) { # or whatever works for your files if ( open( IN, "<", $infile )) { local $/ = undef; $_ = ; close IN; emitter->print( $parser->( $_ )); } else { warn "unable to open $infile: $!\n"; } } #### package TestParsers; sub file_type_A { local $_ = shift; # parameter is full text of file chomp; my @field_labels = qw/date result tester/; # common pieces of data my %field_content; @field_content{@field_labels} = ( split /\|/ )[1,4,6]; return \%field_content; } # more subs for other formats... (B, C, etc) sub new { my $sub_hash = ( 'Gearbox/Integration' => \&file_type_B, 'Gearbox/Assembly' => \&file_type_A, ... 'Brakedrum/Performance' => \&file_type_A, ... # diff. paths might use same func ); return $subhash{$_[0]} }