in reply to compare csv files only to first fullstop character

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

Replies are listed 'Best First'.
Re^2: compare csv files only to first fullstop character
by john.tm (Scribe) on May 08, 2014 at 18:22 UTC
    please see screen print when i run this script
    C:\scripts>new2.pl Backslash found where operator expected at C:\scripts\new2.pl line 47, + near "(my $serverKey = $server) =~ s/\" (Might be a runaway multi-line // string starting on line 38) (Missing operator before \?) Global symbol "$serverKey" requires explicit package name at C:\script +s\new2.pl line 38. syntax error at C:\scripts\new2.pl line 47, near "(my $serverKey = $se +rver) =~ s /\" Global symbol "$serverKey" requires explicit package name at C:\script +s\new2.pl line 49. Global symbol "$serverKey" requires explicit package name at C:\script +s\new2.pl line 57. Global symbol "$serverKey" requires explicit package name at C:\script +s\new2.pl line 58. Global symbol "$serverKey" requires explicit package name at C:\script +s\new2.pl line 58. Execution of C:\scripts\new2.pl aborted due to compilation errors.
      Your Perl is probably older than 5.10, so you can't use the defined-or operator. See perl5100delta for details.
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        i use perl 5.8.8 , any way round it?
      Check line 38. If it is like this $_ ///= '-- missing --' for $status, $ticket, $resolution; then delete one of the /, there should only be 2.
      poj
        poj there are only 2 // on that line??
      i replaced the new defined-or operator on line 38. with ||.
A reply falls below the community's threshold of quality. You may see it by logging in.