Solved

Debug use of uninitialized value

Posted on 2003-10-26
3
204 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
perl rename 2 142
Having a problem with ActiveState Perl on 64-bit Windows 7 3 72
Extract data from span tag 1 92
Perl Write to Specific line in a file 15 88
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

815 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

9 Experts available now in Live!

Get 1:1 Help Now