Loading ...
Sorry, an error occurred while loading the content.

Use of uninitialized value error

Expand Messages
  • Denny Malloy
    Hi, I keep getting an uninitialized error and I do not know how to fix it. I know that you can normally fix this by assigning blanks to it but I am getting
    Message 1 of 6 , May 1, 2003
    • 0 Attachment
      Hi,

      I keep getting an uninitialized error and I do not know how to fix it. I
      know that you can normally fix this by assigning blanks to it but I am
      getting this error on an array element.

      Let me explain the code a little first. I have an input file that has 20
      fields delimited by the "|" symbol. The first thing I do is read in the
      input file and split each line into two different elements in an array.
      Then I go through the array and check different fields for different
      conditions. If they meet that condition I push those certain records into
      another array. But when I check the array element using an if statement and
      that element is empty I get the uninitialilized error. It is normal for a
      lot of these elements to be empty. Below is an example of the input file
      and my code. I am open for suggestions to make this code a lot better.
      This is only a small section of the code. I will be checking almost every
      field for different conditions.


      ## Data file ###
      000|0000000||AU||EX|03-04-2003|OR|6526584|2|2.16||||SR|03-04-2003|OR|6526584
      |||
      000|0000000||AU||EX|03-04-2003|XR|6526584|2|2.15||||SR|03-04-2003|XR|6526584
      |||
      000|0000000||AU||EX|03-04-2003|XR|6526584|2|2.17||||SR|03-04-2003|XR|6526584
      |||
      000|0000000||AU||EX|03-04-2003|OR|6526585|2|7||||SR|03-04-2003|OR|6526585|||

      000|0000000||AU||EX|03-04-2003|XR|6526585|2|206||||SR|03-04-2003|XR|6526585|
      ||
      128|206.14||AU|3761|EX|03-04-2003|XR|6526585||||||||||||

      128|206.19||AU|3761|EX|03-04-2003|XR|6526585||||||||||||


      my @code=();
      while(<IFILE>){
      chomp;
      my (@parts)=split /\|/, $_;

      if($parts[8] ne "" && $parts[8] ne " "){
      my $exline = join "|",@parts[0..8,18,19];
      push @code, $exline;
      }
      if($parts[17] ne "" && $parts[17] ne " "){
      my $srline = join "|",@parts[9..19];
      push @code, $srline;
      }
      }

      foreach(@code){
      my (@fl)=split /\|/, $_;

      if (($fl[4] eq "" && ################################ get error here
      ######################
      $fl[9] ne "***" && $fl[9] !~ /AAA/i &&
      ($fl[5] eq "" || $fl[5] eq " ") &&
      $fl[2] =~ /^DIG/i) || $fl[5] =~ /^CP/i ){
      push @digest, $_;
      }
      }

      Dennis Malloy
      Systems Programmer
      NPC, Inc.
      Old Route 220
      P.O. Box 373
      Claysburg, PA 16625
      www.npcweb.com
      814 239.8787
      Fax: 814 239.0105
      denny.malloy@...
    • Jonathan Dunn
      On Thu, 1 May 2003 10:15:02 -0400, Denny Malloy wrote ... well, you didn t declare @digest ...
      Message 2 of 6 , May 1, 2003
      • 0 Attachment
        On Thu, 1 May 2003 10:15:02 -0400, Denny Malloy wrote
        > Hi,
        >
        > I keep getting an uninitialized error and I do not know how to fix
        > it.

        well, you didn't declare @digest ...
      • Denny Malloy
        On Thu, 1 May 2003 10:15:02 -0400, Denny Malloy wrote ... well, you didn t declare @digest ... I did at the top of my code. I didn t post that part. Sorry!
        Message 3 of 6 , May 1, 2003
        • 0 Attachment
          On Thu, 1 May 2003 10:15:02 -0400, Denny Malloy wrote
          > Hi,
          >
          > I keep getting an uninitialized error and I do not know how to fix
          > it.

          well, you didn't declare @digest ...

          I did at the top of my code. I didn't post that part. Sorry!



          Unsubscribing info is here:
          http://help.yahoo.com/help/us/groups/groups-32.html

          Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
        • Jenda Krynicky
          From: Jonathan Dunn ... the uninitialized error is NOT related to variable declaration at all! Try #!perl -w my $foo; print
          Message 4 of 6 , May 1, 2003
          • 0 Attachment
            From: "Jonathan Dunn" <jon@...>
            > On Thu, 1 May 2003 10:15:02 -0400, Denny Malloy wrote
            > > Hi,
            > >
            > > I keep getting an uninitialized error and I do not know how to fix
            > > it.
            >
            > well, you didn't declare @digest ...

            the uninitialized error is NOT related to variable declaration at
            all! Try

            #!perl -w
            my $foo;
            print "foo=$foo\n";

            Is $foo declared? Yes!
            Is $foo initialized? No!

            All the warning says is that the value of the variable was undef.
            Nothing more. This might happen because you forgot to assign a value
            to the variable, because you undef()ed the variable or because the
            function whose return value you assigned to the variable returned
            undef:

            #!perl -w
            my $foo = 5;
            print "foo=$foo\n";
            undef $foo;
            print "foo=$foo\n";


            IMHO this particular warning is pretty useless. And very often
            annoying.

            Jenda
            ===== Jenda@... === http://Jenda.Krynicky.cz =====
            When it comes to wine, women and song, wizards are allowed
            to get drunk and croon as much as they like.
            -- Terry Pratchett in Sourcery
          • Charles K. Clarkson
            Denny Malloy wrote: When I tested your script I found more uninitialized errors than you indicated. ... The problem is in both your
            Message 5 of 6 , May 1, 2003
            • 0 Attachment
              Denny Malloy <denny.malloy@...> wrote:

              When I tested your script I found more
              uninitialized errors than you indicated.

              : my @code=();
              : while(<IFILE>){
              : chomp;
              : my (@parts)=split /\|/, $_;

              The problem is in both your 'split's.

              Here is an excerpt form perlfunc on split:

              If LIMIT is specified and positive, splits into no more
              than that many fields (though it may split into fewer).

              If LIMIT is unspecified or zero, trailing null fields
              are stripped (which potential users of pop would do
              well to remember).

              If LIMIT is negative, it is treated
              as if an arbitrarily large LIMIT had been specified.

              This means that you should place a -1 as the third
              argument in your split.


              my (@parts) = split /\|/, $_, -1;


              By doing do, you will allow the null fields at the
              end of your file to be filled.
              :
              : if($parts[8] ne "" && $parts[8] ne " "){
              : my $exline = join "|",@parts[0..8,18,19];
              : push @code, $exline;
              : }
              : if($parts[17] ne "" && $parts[17] ne " "){
              : my $srline = join "|",@parts[9..19];
              : push @code, $srline;
              : }
              : }
              :
              : foreach(@code){
              : my (@fl)=split /\|/, $_;

              my @fl = split /\|/, $_, -1;


              HTH,

              Charles K. Clarkson
              --
              Head Bottle Washer,
              Clarkson Energy Homes, Inc.
              Mobile Home Specialists
              254 968-8328
            • Denny Malloy
              my (@parts) = split / |/, $_, -1; Thanks again Charles. I did not realize null fields where not being stripped. I guess I should read Programming Perl
              Message 6 of 6 , May 1, 2003
              • 0 Attachment
                my (@parts) = split /\|/, $_, -1;

                Thanks again Charles. I did not realize null fields where not being
                stripped. I guess I should read "Programming Perl" again.
              Your message has been successfully submitted and would be delivered to recipients shortly.