Any help figuring out the logic would be appreciated.
I have 2 files
names.log and report.rpt
names.log contains:
tomjr
billsv
terrytv
report.rpt contains:
tomjr logged in at 10am
puppychow logged in at 11am
billsv logged in at 12pm
kittycat logged in at 1pm
I want to parse the report.rpt file. If a user from names.log is in the report.rpt file then print the entire line to a 3rd file(output.log)
I will post my code below. The problem I am having is the nested $_ in the foreach loop.
ARGV[0]=names.log
ARGV[1]=report.rpt
ARGV[2]=output.log
############################################################
open(OUTPUTLOG,">>$ARGV[2]") || die "Couldn't create the file\n";
my $userlist="$ARGV[0]";
open (ULIST, $userlist);
chomp(@userlist=<ULIST>);
foreach $_ (@userlist) {
open (DATA, "$ARGV[1]") || die "Couldn't open file\n";
while (<DATA>) {
if (m/$_/) {print }
}
}
close DATA;
close OUTPUTLOG;
########################################################
I have 2 files
names.log and report.rpt
names.log contains:
tomjr
billsv
terrytv
report.rpt contains:
tomjr logged in at 10am
puppychow logged in at 11am
billsv logged in at 12pm
kittycat logged in at 1pm
I want to parse the report.rpt file. If a user from names.log is in the report.rpt file then print the entire line to a 3rd file(output.log)
I will post my code below. The problem I am having is the nested $_ in the foreach loop.
ARGV[0]=names.log
ARGV[1]=report.rpt
ARGV[2]=output.log
############################################################
open(OUTPUTLOG,">>$ARGV[2]") || die "Couldn't create the file\n";
my $userlist="$ARGV[0]";
open (ULIST, $userlist);
chomp(@userlist=<ULIST>);
foreach $_ (@userlist) {
open (DATA, "$ARGV[1]") || die "Couldn't open file\n";
while (<DATA>) {
if (m/$_/) {print }
}
}
close DATA;
close OUTPUTLOG;
########################################################