Solved

Debug use of uninitialized value

Posted on 2003-10-26
3
184 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
Comment Utility
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
Comment Utility
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
Comment Utility
inq123, you are correct.  It was a typo.  Thanks.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Sending email via Perl on Windows 3 124
perl script 4 93
hard perl script 16 146
Perl Script - Remove column of data based on column value 2 48
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

7 Experts available now in Live!

Get 1:1 Help Now