Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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."


In reply to The simplest possible pattern match defeats me by logan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-04-19 00:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found