Sorry guys/gals, I should have posted this right from the beginning.... But here is the entire script.#!/usr/bin/perl use warnings; use strict; my $dircom="completes"; my (@exch, @files, @completefile); my ($su_adapter,$su_date,$su_time,$su_gateway,$su_message); my ($dc_adapter,$dc_date,$dc_time,$dc_gateway,$dc_message); my ($file, $exch); my ($line, $downloadline, $startline, $i, $in); opendir MYDIR, "$dircom"; @files = grep !/^\.\.?$/, readdir MYDIR; close (MYDIR); @exch = ("EXCH1","EXCH2","EXCH3","EXCH4","EXCH5"); open (LIS, "+>list.txt") || die ("Can't open list.txt"); foreach $file(@files) { open (FIL, "completes\\$file") || die ("test"); my $cnt=0; while (<FIL>) { $in="$_"; chomp($in); $completefile[$cnt]="$in"; $cnt++; }; close FIL; print LIS "\n$file\n"; foreach $exch(@exch) { for($i=0; $i<=$#completefile; $i++) { #no warnings 'uninitialized'; if($completefile[$i]=~ m/^.+\\(.+)_.+\..+?:(.+?)\s-\s(.+?) +\s.+\/($exch)\s\|.+::(.*Up)\(\)/) { $su_adapter=$1; $su_date=$2; $su_gateway=$4; $su_message=$5; $su_time=$3; $line=$i; }; }; for($i=0; $i<=$#completefile; $i++) { #no warnings 'uninitialized'; if($completefile[$i]=~ m/^.+\\(.+)_.+\..+?:(.+?)\s-\s(.+?) +\s\|\s.+?\/($exch)\s\|\s([Cc]ontract download complete)/){ $dc_adapter=$1; $dc_date=$2; $dc_gateway=$4; $dc_message=$5; $dc_time=$3; $downloadline=$i; }; }; for($i=0; $i<=$#completefile; $i++) { #no warnings 'uninitialized'; if($i == $line) { print LIS "$su_adapter, $su_date, $su_time, $su_gatewa +y, $su_message\n"; }; if($i == $downloadline) { print LIS "$dc_adapter, $dc_date, $dc_time, $dc_gatewa +y, $dc_message\n"; }; }; }; }; close LIS;
... where I need to grab and use the info in the matched string. My problem is that I can't seem to figure out how to clear the variable for the next match. If the "$exch" doesn't exist in the file, it continues on, but keeps and prints out the info from the previous run where the $exch existed. So I end up getting data from a previous match listed in the next output. I've undef'd the $su_adapter, etc, but I believe it's being held in the $1, $2, because there was nothing to overwrite it.
I hope I'm explaining the well enough....In reply to undef a variable for a loop by csiepka
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |