bbb has asked for the wisdom of the Perl Monks concerning the following question:
Hi fellow Monks!
I am encountering this error "Use of uninitialized value $word in print at C:\test\test.pl" every time I put anchors ^ or $ beside the variable $key. My goal here is to grab the exact searchword in the list and return its corresponding website. I am having trouble when in case that my searchword is "ICS" (which has an empty website in the list) but instead returning "TRONICS" which has a value.
Here is my code:
my $key = "searchword"; my $path = "C:\\test\\list.txt"; open(INFILE, "<$path"); while (<INFILE>) { if ( /^$key\t(www\.[^.]*\.com)/i ) { my $word = $1; } } print $word; close(INFILE);
Thank you in advance for adding your inputs in to this one!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Use of uninitialized value in regexp
by Athanasius (Archbishop) on Feb 09, 2015 at 06:42 UTC | |
by bbb (Novice) on Feb 10, 2015 at 00:43 UTC | |
by AnomalousMonk (Archbishop) on Feb 10, 2015 at 01:17 UTC | |
by bbb (Novice) on Feb 17, 2015 at 01:12 UTC |