Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8502407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:28:36+00:00 2026-06-11T01:28:36+00:00

I’m getting a warning running one of my Perl scripts. The error is being

  • 0

I’m getting a warning running one of my Perl scripts. The error is being thrown at a simple if statement where I’m testing if a string in an array is equal to another string.

My coworker and I have tried several scenarios and still haven’t been able to resolve the warnings. I’ve tried to place all my research so far into this thread, so it is a little long, but please stick with it. I’m completely stuck and hoping one of the great minds of Stack Overflow can help me out!

The code generating the problems is:

if ($pieces[0] eq "PromotionNumber")

The block of code around that section is:

my @pieces = split(/=/, $var);
if($pieces[0] eq "PromotionNumber") {
     $promoNumber = $pieces[1];
} elsif ($pieces[0] eq "Type") {
# More similar code follows

My goal in the above code is to assign all the variables I’ve found in a text file to the respective Perl variables. I then insert those found variables into a SQL database.

The text file has several fields that can be in different orders, which is why I use the switch style if-elsif… to accomplish assigning values. There are also some fields I don’t care about, such as Level, and I just ignore these fields. These fields however are the fields that cause warnings.

The $var is set to the following as it loops through…

PromotionNumber=000
RecordOffset=0
Code=0
SubCode=1
Level=0

When I hit “Level=0”, I can pause in the PerlIDE.exe debugger and see that the string is split into Level and 0 and inserted in the array. However, as soon as the code advances to the if statement and tests $pieces[0] eq "PromotionNumber" I get the warning.

I can even print out $pieces[0] right before the if statement, and it will print “Level”.

If I change the code to the following the warning goes away…

my @pieces = split(/=/, $var);
if($pieces[0] eq "Level") {
    #My problematic variable test
}elsif($pieces[0] eq "PromotionNumber") {
     $promoNumber = $pieces[1];
} elsif ($pieces[0] eq "Type") {
#More similar code follows

However, if I test for the “Level” string second, the warning comes back. The code below DOES have the warning.

my @pieces = split(/=/, $var);
if($pieces[0] eq "PromotionNumber") {
    #My problematic variable test
}elsif($pieces[0] eq "Level") {
     $promoNumber = $pieces[1];
} elsif ($pieces[0] eq "Type") {
#More similar code follows

Why does Perl care which order I test in? Note, that I am testing SEVERAL other strings that are multiple elsif’s down in my if-elsif statements that don’t give this warning.

Any ideas? I really need to clear up this warning so that it doesn’t flood the console when running. The script is working with the warnings though.

Exact error is:

Use of uninitialized value in string eq at japdpmrijob.pl line 250.

Exact line of error (determined using Perl’s debug utility in PerlIDE.exe) is:

if ($pieces[0] eq "PromotionNumber") {

I can print out $pieces[0] and see the value. So I know it is defined with my value. I can also print out $pieces[1] and see my expected value. If I test for $pieces[0] eq “Level” first, the warning goes away and I can access both variables.

I am still confused…

It looks like the error is actually the “eq” being flagged as a variable. Any ideas on that?

Below you’ll find a large chunk of the code. I included the entire for loop and several of the variables that I’m working with. Notice the else statement at the end of the if-elsif-else sequence, I added this to attempt stop the warning as noted by the third answer. This else statement prints my expected values every time the warning is called, so I know the values are present.

for my $cond (@conditions) {
    if($debug==1){print $cond."\n";}

    # Required database variables
    my $isRecord = 0;
    my $promoNumber;
    my $type;
    my $process;
    my $testValue;
    my $recordOffset;
    my $code;
    my $subcode;
    my $itemType;
    my $itemValue;

    # Function test variables
    my $itemTypeVar;
    my $newQualifier = 1;

    # Database Configuration
    my $dbApps = new Win32::ODBC("myDatabase") || die "Error: " . Win32::ODBC::Error();
    my @condVars = split(/\|/, $cond);
    for my $var (@condVars) {
        if($debug==1){print $var."\n";}
        my @pieces = split(/=/, $var);
        if( defined($pieces[0]) ){
            print "piece 0 defined!\n";
        } else {
            print "pieces 0 not defined!\n";
        }
        if( defined($pieces[1]) ){
            print "piece 1 defined!\n";
        } else {
            print "piece 1 not defined!\n";
        }
        if($pieces[0] eq "PromotionNumber"){
            $promoNumber = $pieces[1];
        } elsif ($pieces[0] eq "Type"){
            $type = $pieces[1];
        } elsif ($pieces[0] eq "Process"){
            $process = $pieces[1];
        } elsif ($pieces[0] eq "TestValue"){
            $testValue = $pieces[1];
        } elsif ($pieces[0] eq "RecordOffset"){
            $recordOffset = $pieces[1];
            if ($recordOffset == 0) {
                $newQualifier = 1; }
        } elsif ($pieces[0] eq "Code"){
            $code = $pieces[1];
        } elsif ($pieces[0] eq "SubCode"){
            $subcode = $pieces[1];
        } elsif ($pieces[0] eq "ItemType"){
            $itemType = $pieces[1];
            if($itemType eq "0") {
                $itemTypeVar = "ItemCode";
            } elsif($itemType eq "1") {
                $itemTypeVar = "ItemCode";
            } elsif($itemType eq "2") {
                $itemTypeVar = "Department";
            } elsif($itemType eq "5") {
                $itemTypeVar = "MixMatchCode";
            } elsif($itemType eq "12") {
                $itemTypeVar = "GroupCode";
            }
        } elsif ($pieces[0] eq $itemTypeVar){
            $itemValue = $pieces[1];
        } else {
            print "$pieces[0] and $pieces[1] not used.\n";
        }
        print "$var\n";
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:28:38+00:00Added an answer on June 11, 2026 at 1:28 am

    I think you are looking for the error in the wrong place. For a warning triggered inside an if-elsif-else statement or other complex block of code, older versions of Perl may identify the warning as occuring on the first line of the statement.

    ------ warn.pl ------
    my $x = 0;
    my $y;
    if ($x == 1) {         # line 3
    } elsif ($x == 2) {
    } elsif ($x == 3) {
    } elsif ($y == 4) {    # line 7
    }
    
    $ perl5.14.2 -w warn.pl
    Use of uninitialized value $y in numeric eq (==) at warn.pl line 7.
    
    $ perl5.8.6 -w warn.pl
    Use of uninitialized value in numeric eq (==) at line 3.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.