use strict; use warnings; use POSIX qw( strftime ); use Text::CSV qw( ); use Tie::File qw( ); use constant INHOUSE =>"Open House Information"; { my $today = strftime('%Y/%m/%d', localtime()); tie(my @db, 'Tie::File', 'dbase1.exm') or die("Unable to open database: $!\n"); my $csv = Text::CSV->new(); foreach my $line (@db) { $csv->parse($line) or die("Unable to parse \"$line\"\n"); my @fields = $csv->fields(); my ($status, $date) = $fields[22, 23]; # Convert date to sortable format. my ($m, $d, $y) = split(/\//, $date); $date = "20$y/$m/$d"; my $kill = ($date < $today); # Are you sure this isn't backwards? if ($status eq INHOUSE && $kill) { $status = ''; } # Reassemble the line and updated the file. $fields[22] = $status; $csv->combine(@fields) or die("Unable to recreate line from fields @fields\n"); # Changing $line causes the file to be updated. $line = $csv->string(); } untie @db; }