I have this 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;
Sorry guys/gals, I should have posted this right from the beginning.... But here is the entire script.

... 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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.