Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

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
0
uluttrell
Asked:
uluttrell
1 Solution
 
seesikCommented:
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.
0
 
inq123Commented:
it's a typo that you used $rcpt on line 23 instead of $rcpts, of course -w would complain it's uninitialized.

BTW, at first I thought you said you got the error from inq123's code. :-)  I did replied with code for your questions a couple times I think.
0
 
uluttrellAuthor Commented:
inq123, you are correct.  It was a typo.  Thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now