Solved

Debug use of uninitialized value

Posted on 2003-10-26
3
195 Views
Last Modified: 2010-03-05
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
Comment
Question by:uluttrell
3 Comments
 
LVL 1

Expert Comment

by:seesik
ID: 9624133
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
 
LVL 8

Accepted Solution

by:
inq123 earned 50 total points
ID: 9624724
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
 

Author Comment

by:uluttrell
ID: 9624785
inq123, you are correct.  It was a typo.  Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now