!/usr/bin/perl -w use Time::Local; use strict; use warnings; use diagnostics; use Data::Dumper; # declare stuff to avoid errors my (%user_bs $user_bs @temp, @temp2, @user_expiration_inf, $firstname, $current, $username, $lastname, $lastlogin, $tokenexpiration, $month, $day, $year, $edate, $line, $line2, $bs, $b1, $y, $z, $name, $name2); our $/; $current = time(); # slurp up the first file into one huge hash ( name => value ) open(BSFILE, "< file1.csv") || die("Can't open file1.csv: $!\n"); while (defined ($line=)) { next if $line =~ /^Data here/; chomp $line; ($b1, $y, $z) = split(/,/, $line); $name = "$z $y"; $user_bs{ $name } = $b1; } close(BSFILE); # Now to whack file two into an array of arrays. open(USERLIST, $ARGV[0]) || die("Can't open $ARGV[0]: $!\n"); while (<>) { next if /^Default Login/; # ignore first line ($username, $lastname, $firstname, $lastlogin, $tokenexpiration) = split(",", $_))[0, 1, 2, 5, 8]; ($month, $day, $year) = split('/', $tokenexpiration); $edate = timelocal(00,00,00,$day,$month-1,$year-1900); next if $edate < $current; # remove from list all users whose tokens expired before today $name2 = "$firstname $lastname"; @temp2 = ($username, $name2, $lastlogin, $tokenexpiration); push @user_expiration_inf, [@temp2]; } close(USERLIST); open(OUT, ">>results.csv") || die("Can't open results.csv: $!\n"); print OUT "User, Data Here, Username, Last login, Token expiration date\n"; # nice while loop to iterate through the array of arrays my $i = 0; while ($user_expiration_inf[$i][1]) { print OUT "$user_expiration_inf[$i][1], $user_bs{$user_expiration_inf[$i][1]}, $user_expiration_inf[$i][0], $user_expiration_inf[$i][2], $user_expiration_inf[$i][3]\n"; $i++; }