Why am i getting "Use of uninitialized value $bo_plus in substitution (s///)

this script pick up a file and steps through it, and then picks up another file and matches the item number to merge the file and i getting this error, and I do not know why ?

here is the code where the file is blowing up with the following errors repeatedly.

substr outside of string at ./parseOsc.pl line 272, <PLUS> line 745800.
substr outside of string at ./parseOsc.pl line 273, <PLUS> line 745800.
Use of uninitialized value $bo_plus in substitution (s///) at ./parseOsc.pl line 283, <PLUS> line 745800.
Use of uninitialized value $res_plus in substitution (s///) at ./parseOsc.pl line 284, <PLUS> line 745800.
Use of uninitialized value $res_plus in string eq at ./parseOsc.pl line 286, <PLUS> line 745800.
Use of uninitialized value $bo_plus in string eq at ./parseOsc.pl line 287, <PLUS> line 745800.

while(<PLUS>) {
     $the_plus = $_;
     $item_plus = substr($the_plus, 0,10);
     $bo_plus   = substr($the_plus,36, 5);
     $res_plus  = substr($the_plus,41, 5);

   next if $item_plus =~ m/\s*MSC/i;
     $item_plus =~ s/\s+//;
     next if $item_plus eq "";
   #print " $item  >$item_plus< \t $bo_plus  \t $res_plus \n";
   $bo_plus  =~ s/\s+//; ### Error happens here !!!
   $res_plus =~ s/\s+//; ### Error happens here !!!

         $res_plus = ($res_plus eq "" ) ? '0' : $res_plus;
        $bo_plus = ($bo_plus eq "" ) ? '0' : $bo_plus;
        next if ( $item ne $item_plus);

     if ( $item eq $item_plus ) {
        #$comingSoon = (( $onhand + $transit) - ( $res_plus + $bo_plus ));
        $comingSoon = (($transit) - ( $res_plus + $bo_plus ));
        if ( $comingSoon > 0 ) {
           $csoon = "Available < 35 days (" . $comingSoon .")";
        } else { $csoon = ""; }
        #  print "$comingSoon \t $onhand \t $transit \t $res_plus \t $bo_plus \n";  
Any Help would be appreciated !
thanks in advance
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It's telling you that line 745,800 of your file is less than 36 characters long.  Since the substr use to set $bo_plus and $res_plus are out of range they return undef (so $bo_plus and $res_plus are undef).  Therefore, you get the undef errors when you try to use them in substitutions.
SandwickAuthor Commented:
$bo_plus and $res_plus are values in a fixed file, that i am picking up and comparing.

is there a way to skip that line, there error must be happening where there is a 0.0 on the line only  ?

See text below

13-5  1 1                11.00    0    0  58  41  12   0.0   1795806216617
13-6  1 1                11.00    0    0  58  41  12   0.0   1795806216624
14-1  1 2                 4.00    0    0  14  14  37   0.0   1795806151734
15-4  1 1   14   10   21 24.00    0    0  25  13  37   0.0   1795806210295
15-6  1 1   15   12   21 20.00    0    0  43  20  21   9.0   1795806210318
15-7  1 1   50   18   50 15.00    0    0  48  34  43   0.0   179580621032
After (or even before) this line:
you could put this:
     next if length($the_plus) < 36;
to skip short lines, if that is the issue.  Change the '36' to other lengths if required.

For debugging you could temporarily add this before my "next..." line:
    print length($the_plus) . "=$the_plus\n";
That should print the length of the line, then an '=' sign and the actual line.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

SandwickAuthor Commented:
Here is what the file looks like, the substr is there and goes past the 41st position.  See image
Hi Sandwick,

I can't see why you're still getting those errors, sorry.  I can't even reproduce them with the code and data you've provided, even without my "next..." command.  If you want to see the code and data I'm using, let me know.

I suggest you copy your script and cut it down as far as you can while still getting the errors.
Do the same with the data (i.e. cut it down until you just have a couple of lines - maybe have the 1st line work and the 2nd creates the errors).
If the cause is then not obvious to you, post your cut down code and cut down data here, along with the errors you're getting from it.

I assume you are getting those errors because you are using "use strict;" and/or "use warnings;", but I don't see those in your script snippet.
...It's about making a Short, Self Contained, Correct (Compilable), Example:
See: http://sscce.org

Often doing this will help you to solve the problem yourself, but it should also make it faster and easier for others to solve it for you.
SandwickAuthor Commented:
I will try to isolate it further, The weird this is, the line is longer then the substr, and I am getting the errors.

is there a way to send the line to the screen as I step through the file ? then I can compare what is being imported and what is being picked up ?
Yes there is a way.  Did you read the 2nd paragraph of my first post?
Can you post an attachment of say the 5-10 lines before and after the line with the error?  That way, we can make sure we have the exact format (rather than copy-paste your text post above which may not be exactly the same as your file).
SandwickAuthor Commented:
tel2 -> your response to put " next if length($the_plus) < 36;" does work, I put it in the wrong location.

thanks !
OK Sandwick,

Glad to hear it's sorted.

I suggest you use that "Short, Self Contained, Correct (Compilable), Example" method wherever you reasonably can.  I find it often helps me to solve my own problems.

And the other learning point I see from this thread is carefully reading through the posts supplied by experts.  You seem to have misread my first post in 2 areas, i.e. where to insert the "next..." line, and the fact that I had already given you debugging info before you asked for it.  If you take heed of this point, then you could save yourself and experts a lot of time in future.

Are you now saying there are lines which are less than 36 chars long in the input file?  Is line # 745800 one of them?  The ones you showed us didn't seem to be that short, so what's the story?

And if you want to make this:
    $the_plus = $_;
a bit (or even a byte) more concise, you can replace it with:
    $the_plus = $_;
or even:
    chomp($the_plus = $_);

Hi Sandwick,
Thanks for the points, but I would have thought they should have been split over wilcoxon and me.  He did the hard work of working out where the problem was.  I just gave you some code to avoid the issue he'd identified, etc.
SandwickAuthor Commented:
I did not know i could split the points, was not that obvious. will pay more attention next time !

thanks for everyones help.
If you want to, I believe you still can (worst case ask an admin to do it for you).
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.