#!/usr/bin/perl use warnings; use strict; use constant CSV_COLUMNS => qw( file analog_id analog_cid epp_res_ck note ); header(); #my @substation_files = glob( "*_subeditor.xml" ); my @substation_files = qw( test1.xml test2.xml ); if (@substation_files == 0) { die "No _subeditor.xml files found.\n" } run_per_file($_) foreach @substation_files; #************************************************** # # sub run_per_file { my ($xml_file) = @_; my %csvdata; #my @vars = qw( file analog_id analog_cid epp_res_ck note); #$csvdata{$_} = '' foreach @vars; $csvdata{$_} = '' foreach (CSV_COLUMNS); $csvdata{file} = $xml_file; $csvdata{analog_cid} = "test.53.cb.stts"; $csvdata{epp_res_ck} = find_epp(\%csvdata); return unless $csvdata{epp_res_ck} ne ''; print_line(\%csvdata); } sub find_epp { my $hr = shift; if($hr->{file} eq "test1.xml") { return 'DEVTYPE=SW'; } else { $hr->{note} .= ":error @ find_epp. "; print_line($hr); return ''; } } sub print_line { my $hr = shift; #print "$hr->{file}, $hr->{analog_id}, $hr->{analog_cid}, $hr->{epp_res_ck}, $hr->{note}\n"; my $string = join ',', map {"$hr->{$_}"} ( CSV_COLUMNS ); print $string, "\n"; } ######################################################### # # subroutine to print header information, csv format. # sub header { my $timestamp=localtime; $timestamp =~ s/(.*) (\d{4})/$2 $1/; print "report generated by $0\n"; print "$timestamp\n"; print "This program does something. \n\n"; #print "Substation filename,analog_id,analog_cid,epp_res_ck, note\n"; print join ',',( CSV_COLUMNS ); print "\n"; } __DATA__ report generated by printsub.pl 2011 Wed Nov 9 10:16:50 This program does something. file,analog_id,analog_cid,epp_res_ck,note test1.xml,,test.53.cb.stts,DEVTYPE=SW, test2.xml,,test.53.cb.stts,,:error @ find_epp.