Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

The simplest possible pattern match defeats me

by logan (Curate)
on May 23, 2013 at 02:35 UTC ( #1034839=perlquestion: print w/ replies, xml ) Need Help??
logan has asked for the wisdom of the Perl Monks concerning the following question:

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."

Comment on The simplest possible pattern match defeats me
Select or Download Code
Re: The simplest possible pattern match defeats me
by LanX (Canon) on May 23, 2013 at 02:51 UTC
    I'm confused!

    Your code and your error-msgs don't seem to match.

    Where is the pattern match (m//) line 103 ?

    You are identifying :

    if ($oldString eq "Automated") { # Line 103, the one that gives all the trouble.

    which doesn't have a regex but an eq!

    Furthermore this can't be line 103, if your output just 4 lines before logs DEBUG main:::84:.

    Could it be that you are chasing at the wrong place?

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      Fair enough, it's a string compare rather than a pattern match. It's a simple eq, which should compare the string contained in $oldString to the value in quotes. Still, I get that uninitialized value error. The reason that there's a big gap between line 84 and line 103 is that I have a chunk commented out with an =item =cut block. Perhaps this will help. I've removed that block to make sure it wasn't causing the problem.
      80 my $oldString = $allChanges->[$k]->getOldString(); 81 my $newString = $allChanges->[$k]->getNewString(); 82 $logger->debug("oldString = (", $oldString, ")"); 83 $logger->debug("newString = (", $newString, ")"); 84 print Dumper($oldString); 85 sleep 1; 86 87 if ($oldString eq "Automated") { 88 $logger->debug("old string = ", $oldString); 89 $logger->debug("new string = ", $newString); 90 }
      Output:
      INFO main:::78: Change 2 was to the Automated field of testCase HIREX- +16845 on createdDate 2013-05-13 11:34:52 Old String = (Ready For Inte +gration) New String = Automated DEBUG main:::82: oldString = (Ready For Integration) DEBUG main:::83: newString = (Automated) $VAR1 = 'Ready For Integration'; Use of uninitialized value in pattern match (m//) at weeklyAutomationC +hanges.pl line 87. Use of uninitialized value in pattern match (m//) at weeklyAutomationC +hanges.pl line 87. DEBUG main:::352: old string = Ready For Integration DEBUG main:::353: new string = Automated DEBUG main:::355: New string = Automated

      -Logan
      "What do I want? I'm an American. I want more."

        Again the error msgs don't fit!

        That's how it looks like if eq fails:

        DB<100> use warnings; $a eq "a" Use of uninitialized value $a in string eq at ...

        So where is the pattern match (m//) at weeklyAutomationChanges.pl line 87.?

        Are you debugging the right file?

        Which perl version do you use?

        Cheers Rolf

        ( addicted to the Perl Programming Language)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1034839]
Approved by vinoth.ree
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-12-20 19:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (97 votes), past polls