Link to home
Start Free TrialLog in
Avatar of uluttrell
uluttrell

asked on

Debug use of uninitialized value

Hi Experts,
This is not a homework assignment.  I am getting the following error for line 23 of my code.  Would someone please point out what I've done wrong.
Thanks for your help.
===Begin Code.pl
#!/usr/bin/perl -w
# exp3.pl
use strict;
my $file = 'results.txt'; #The results file
my $rfile = 'rcpts.txt';
my $log = 'sample.txt'; #The log file
#my $log = 'log.txt'; #The log file
my $rcpt;
my $rcount;
open(FH, ">>$file") or die "Can't open $file <$!>\n"; #Open the results file
open(LOG, $log) or die "Can't open $log <$!>\n";  # Open the log file
open (RCOUNT, ">$rfile") or die "Can't open $rfile <$!>\n";
while(<LOG>){# While the log file is open do
    chomp;
    if (/patternA/){
    my $fromhost = $1;
    my $rcpts = $2;
    my @rcpts = $rcpts;
    foreach my $rcpt(@rcpts) {
    $rcpt =~ tr/,/,/ ;
    print FH "$fromhost \n";
    print FH "$rcpts \n";
    print RCOUNT "$rcpt \n";
    }
}
close FH;
close LOG;
===End Code.pl
Avatar of seesik
seesik

Assuming that patternA actually captures something, my @rcpts = $rcpts is probably incorrect, unless you want a single-element array. It's more likely that you're forgetting to split the scalar $2 up into list elements and populate @rcpts w/ that. It would be a lot more helpful if you'd post a sample line from each file, as well as the real pattern that you're attempting to match.
ASKER CERTIFIED SOLUTION
Avatar of inq123
inq123

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of uluttrell

ASKER

inq123, you are correct.  It was a typo.  Thanks.