There is altogether too much wrong with that code to comment on everything. So a brief list of the highlights then some sample code that does what you seem to want:

  1. Always use strictures (use strict; use warnings; - see The strictures, according to Seuss).
  2. In many places you use an array (e.g. @SERVER) instead of a scalar ($server).
  3. Use the three parameter open and lexical file handles (open my $fIn, '<', $filename or die "Can't open '$filename': $!\n")
  4. Don't use global variables.
use strict; use warnings; my $masterStr = <<EOF; john.co.uk,Acton,Backup,Team,backup,bkup-01,External gim.com,Acton,Backup Team,backup,bumas1,internal jeff.be.com,Acton,Backup Team,backup,bumas1,internal scream,Acton,Backup Team,backup,bumas1,internal ACTDFVUA.co.uk,Acton,Backup Team,backup,imrn,internal EOF my $dailyStr = <<EOF; Server,Type,Reason,Data at Risk,Ticket,Resolution john.com,F,No email received,YES gim,Acton,Backup Team,backup,bumas1,internal elephant.com,F No email received,YES jeff.co.com,F No email received,YES scream S,1 email received,Some banana,F,No email received,ES EOF my %masters = loadMasters(); my @dateParts = localtime (); my ($day, $month, $year) = @dateParts[3 .. 5]; $year += 1900; $month += 1; #open my $dailyIn, '<', $INFILE1 or die " cannot open '$INFILE1': $!"; open my $dailyIn, '<', \$dailyStr; <$dailyIn>; # Skip header line while (defined (my $line = <$dailyIn>)) { chomp $line; my ($server, $type, $reason, $status, $ticket, $resolution) = split ',', $line; $_ = uc $_ for $server, $type; $_ //= '-- missing --' for $status, $ticket, $resolution; if ($type eq "F") { $type = "BACKUP FAILED"; } elsif ($type eq "S") { $type = "SKIPPED FILES"; $ticket = "DO NOT RAISE TICKET"; } (my $serverKey = $server) =~ s/\..*//; if (!exists $masters{$serverKey}) { print "'$server' not known please update\n"; next; } printf "%s %s %s,%s,%s,%s,%s,%s,%s,%s,%s,%s, \n", $day, $month, $year, $masters{$serverKey}{loc}, $masters{$serverKey}{team}, $masters{$serverKey}{owner}, $server, $type, $reason, $status, $ticket, $resolution; } sub loadMasters { my %masters; #open my $masterIn, '<', $INFILE1 or die " cannot open '$INFILE1': + $!"; open my $masterIn, '<', \$masterStr; while (defined (my $line = <$masterIn>)) { chomp $line; my ($machine, $loc, $team, $software, $backup, $owner) = split + ',', $line; (my $machineKey = uc $machine) =~ s/\..*//; warn "Multiple servers match '$machineKey'!\n" if exists $masters{$machineKey}; $masters{$machineKey} = { server => $machine, loc => $loc, team => $team, software => $software, backup => $backup, owner => $owner }; } return %masters; }

Prints:

9 5 2014,Acton,Backup,bkup-01,JOHN.COM,BACKUP FAILED,No email received +,YES,-- missing --,-- missing --, 9 5 2014,Acton,Backup Team,internal,GIM,ACTON,Backup Team,backup,bumas +1,internal, 'ELEPHANT.COM' not known please update 9 5 2014,Acton,Backup Team,internal,JEFF.CO.COM,F NO EMAIL RECEIVED +,YES,-- missing --,-- missing --,-- missing --, 'SCREAM S' not known please update 'BANANA' not known please update

The open my $masterIn, '<', \$masterStr; stuff uses a string as a file which is handy for test code like this. The commented out open lines are closer to what you would use for real.

You should really use Text::CSV to manage csv files instead of hand rolled split code.

Update: fixed typo in module name.

Perl is the programming world's equivalent of English

In reply to Re: compare csv files only to first fullstop character by GrandFather
in thread compare csv files only to first fullstop character by john.tm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.