in reply to Re: Undef and Uninitialized Issue
in thread Undef and Unitialized Issue

I can't believe I missed that. I had conditioned so many of the other substr's to prevent issues and just complete missed that one. However, after clearing that out I am still getting on uninitialized error. Below is the sample input data and the output up to the error:

INPUT

06 01720168-00000000257980 123 N PLAZA HWY 123 172016-8 SOME COMPANY INC. ANOTHER COMPNAY OF SOMWHERE P O BOX 1234 123 STREET RD. CITY KY 12345 SUITE# 1234 CITY, ST 12345 6/23/2014 $257.98 ANOTHER COMPNAY OF SOMWHERE 6/23/2014 123 STREET RD. 172016-8 6/09/2014 CITY, ST 12345 $257.98 02CS 4/30 5/28 3117.0 3259.0 142.0 Meter # C204508 142.0 232.99 Pipe Replacement Pgm SNR Comm 3.27 RESEARCH & DEVELOPMENT TARIFF .03 3.00% Rate Increase County Co Sc Tax on 236.29 7.09 6.00% State Tax on 243.38 14.60 Current Charges 257.98 Previous Amount Due 351.60 Payment Received 5/22 351.60CR Total Amount Due 257.98 1-877-123-1234 66.0 28 142.0 8:00am to 4:00pm 58.6 30 203.0 70.3 28 174.0

OUTPUT

elt 1 0 is 00001 elt 1 1 is 00001111 elt 1 2 is 06 elt 1 3 is 01720168-00000000257980 elt 1 4 is 172016-8 elt 1 5 is SOME COMPANY INC. elt 1 6 is 123 STREET RD. elt 1 7 is CITY, ST 12345 elt 1 8 is elt 1 9 is ANOTHER COMPNAY OF SOMWHERE elt 1 10 is 123 STREET RD. elt 1 11 is SUITE# 1234 elt 1 12 is CITY, ST 12345 elt 1 13 is ANOTHER COMPNAY OF SOMWHERE elt 1 14 is 123 STREET RD. elt 1 15 is CITY, ST 12345 elt 1 16 is elt 1 17 is 6/23/2014 elt 1 18 is 6/09/2014 elt 1 19 is $257.98 elt 1 20 is $257.98 elt 1 21 is 1-877-123-1234 elt 1 22 is c66.0 elt 1 23 is 58.6 elt 1 24 is 70.3 elt 1 25 is 28 elt 1 26 is 30 elt 1 27 is 28 elt 1 28 is c142.0 elt 1 29 is 203.0 elt 1 30 is 174.0 elt 1 31 is 257.98 Use of uninitialized value in concatenation (.) or string at c:/perl/c +onvert2.pl line 45. elt 1 32 is elt

Replies are listed 'Best First'.
Re^3: Undef and Uninitialized Issue
by Athanasius (Archbishop) on Apr 02, 2015 at 15:29 UTC

    That particular warning comes about because this statement:

    push @TEMP, $cur_amt, $past_amt;

    towards the end of sub formatC2 is called with $past_amt undefined. You can fix this by providing $past_amt with a default value near the start of the subroutine:

    $past_amt = '';

    I tracked this down by looking at the contents of @OUTPUT after the first while loop finishes. As fishmonger says, you can use Data::Dumper or Data::Dump for this. I prefer Data::Dump:

    use Data::Dump; ... while (<$fh>) { chomp; #Removes the control character my @LINES = split(/\n/, $_, -1); #Split on line break creating + array my @RECORDS = formatC2(@LINES); $OUTPUT[$seq_num] = [@RECORDS]; last; } close $fh; dd \@OUTPUT; exit(0);

    The last ensures that I get only the first iteration of the while loop, and the exit helps me to see what I need to see (in this case, the contents of @OUTPUT) by omitting everything that comes after.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      Thank you so much! I realize this may not have been the most difficult thing for your guys to answer and makes me look a bit silly for needing to ask, but I wasn't given a ton of time to work on this particular project and PERL was the only real solution I could find for it.

      I very much like the looks of PERL and think after this project I will be devoting some time to learn it in earnest because it can compliment the work I do already so much.

        Just a quick social note -- if you like the looks of this lovely language, you might want to learn the social conventions that go with it. The purists will read "PERL" and think "uncultivated noob". But when they see you capitalize only the first letter -- "Perl" -- they see you as a brother or sister and it greases the wheel of communication a bit.

        For what it's worth . . .