I'm having a hard time with what seems like a really simple issue: comparing a string to a variable. I've pored over the Camel book and the docs for a disturbing amount of time and I'm stumped by something that hasn't been an issue for me for 15 years. For some reason when I run the code below I keep get warnings about uninitialized values in the pattern match.
while ($allChanges->[$k]) {
$logger->info("Change $k was to the ", $allChanges->[$k]->getField(
+), " field of testCase ", $allChanges->[$k]->getKey(), " on createdDa
+te ", $allChanges->[$k]->printCreatedDate(), " Old String = (", $allC
+hanges->[$k]->getOldString(), ") New String = ", $allChanges->[$k]->g
+etNewString());
local $oldString = $allChanges->[$k]->getOldString();
local $newString = $allChanges->[$k]->getNewString();
$logger->debug("oldString = (", $oldString, ")");
$logger->debug("newString = (", $newString, ")");
print Dumper($oldString);
if ($oldString eq "Automated") { # Line 103, the one that gives all
+ the trouble.
$logger->debug("old string = Automated: ", $oldString);
$logger->debug("new string: ", $newString);
}
}
package ChangeItem;
sub new {
my $class = shift;
my $logger = get_logger("ChangeItem");
my $self = { } ;
if (@_) {
$self->{line} = shift @_;
}
$self->{key} = 0;
$self->{field} = 0;
$self->{oldString} = 0;
$self->{newString} = 0;
$self->{createdDate} = 0;
$self->{version} = 0;
bless ($self, $class);
return $self;
}
sub setOldString {
my $self = shift;
$self->{oldString} = shift;
}
sub getOldString {
my $self = shift;
return $self->{oldString};
}
When I run the code I keep getting warnings about uninitialized values in the pattern match
INFO main:::80: Change 0 was to the Automated field of testCase HIREX-
+16861 on createdDate 2013-05-13 10:16:05 Old String = (To Be Automate
+d) New String = Ready For Integration
DEBUG main:::84: oldString = (To Be Automated)
DEBUG main:::85: newString = (Ready For Integration)
$VAR1 = 'To Be Automated';
Use of uninitialized value in pattern match (m//) at weeklyAutomationC
+hanges.pl line 103.
Use of uninitialized value in pattern match (m//) at weeklyAutomationC
+hanges.pl line 103.
The value of $oldString is populated by a call to ChangeItem::getOldString(). I can see that it has a value because it's being printed. I've checked that the value is a simple scalar by sending it to Data::Dumper ($VAR1 = 'To Be Automated';). I feel like I'm missing something incredibly basic but at this point I'm baffled.
-Logan
"What do I want? I'm an American. I want more."
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.