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

Uninitialized value in concatination or string error question

Expand Messages
  • Electron One
    Hello everyone, I have the code below, and I send it the data below. However, on this small if statement, if(/( S+) s+PIN ? s(L|H)/){ if($Value =~ /$2/){ print
    Message 1 of 4 , May 1, 2003
    • 0 Attachment
      Hello everyone,

      I have the code below, and I send it the data below.

      However, on this small if statement,

      if(/(\S+)\s+PIN\?\s(L|H)/){
      if($Value =~ /$2/){
      print "\nOh yeah LOOK HERE matched";
      }else{
      print "\nError $1 does NOT match in file $File!";
      }
      If I add a $1, to see what was captured, where it says "LOOK HERE" all
      the sudden I get several

      "Use of uninitialized value concatenation (.) or string at programname.pl
      line 25, <FUT> line ..."

      errors. I dont know why adding the $1 there gives me those errors when the
      $1 in the else statement DOESN'T give me the errors. They both are in the
      same logical location, yet one gives me the error and the other doesn't.
      Can anybody explain?

      Greatly appreciated.


      _____________________DATA_________________________________________

      JOE NO OE CELL
      SHMOE PIN_OFF
      WHATEVER PIN? H
      DOESNTMAT PIN? H

      NO_N.MATTER PIN_ON
      ADREG .! PIN_L
      WHOCARES PIN? L
      TEST.ING PIN? H
      JoeSHMOEISCOOL PIN? L
      PERLSGREAT PIN? H
      NOEHEREKL PIN? L
      DKLEREM> PIN? H




      ________________________________________CODE
      BELOW____________________________________
      #!/usr/bin/perl

      use strict;

      my $Value;
      my $File;

      $Value = 0;

      while(<FUT>){
      chomp;
      if(/^\s*$/){
      next;
      }
      if($Value=~ /[LH]/){
      if(/(\S+)\s+PIN\?\s(L|H)/){
      if($Value =~ /$2/){
      print "\nOh yeah LOOK HERE matched";
      }else{
      print "\nError $1 does NOT match in file $File!";
      }
      }else{

      chop($Value);
      redo;
      }
      next;
      }

      if(/PIN_(L|H)/){
      if($1 eq 'H'){
      $Value = 'H';
      next;

      }elsif($1 eq 'L'){
      $Value = 'L';
      next;

      }else{

      print "\nError in code."; #Should never arrive here
      }
      }
      }


      close(FUT);
    • Charles K. Clarkson
      ... It worked fine when I tested it. Perhaps you could send a larger code fragment. $_ = www PIN? H ; foreach my $value ( qw| H K L M | ) { if (
      Message 2 of 4 , May 1, 2003
      • 0 Attachment
        Electron One <electron1@...> wrote:

        : I have the code below, and I send it the data below.
        :
        : However, on this small if statement,
        :
        : if(/(\S+)\s+PIN\?\s(L|H)/){
        : if($Value =~ /$2/){
        : print "\nOh yeah LOOK HERE matched";
        : }else{
        : print "\nError $1 does NOT match in file $File!";
        : }
        : If I add a $1, to see what was captured, where it says
        : "LOOK HERE" all the sudden I get several "Use of
        : uninitialized value concatenation (.) or string at:
        : programname.pl line 25, <FUT> line ..." errors. I dont
        : know why adding the $1 there gives me those errors when
        : the $1 in the else statement DOESN'T give me the errors.
        : They both are in the same logical location, yet one
        : gives me the error and the other doesn't.
        : Can anybody explain?

        It worked fine when I tested it. Perhaps you could
        send a larger code fragment.


        $_ = 'www PIN? H';

        foreach my $value ( qw| H K L M | ) {

        if ( /(\S+)\s+PIN\?\s(L|H)/ ) {
        if($value =~ /$2/){
        print "\nOh yeah LOOK HERE matched";
        }else{
        print "\nError $1 does NOT match in file";
        }
        }
        }



        HTH,

        Charles K. Clarkson
        --
        Head Bottle Washer,
        Clarkson Energy Homes, Inc.
        Mobile Home Specialists
        254 968-8328
      • Electron One
        Well that s strange. Ok, here is my COMPLETE code. This code has the $1 included in both the if and the else statement. You should get the same error I
        Message 3 of 4 , May 1, 2003
        • 0 Attachment
          Well that's strange. Ok, here is my COMPLETE code. This code has the $1
          included in both the if and the else statement. You should get the same
          error I mentioned in my first email, but if you take out $1 in the if(still
          leaving it in else), the error goes away. Why?

          ________________________________________________________________________________

          #!/usr/bin/perl

          use strict;

          my $Value;
          my $File;

          $Value = 0;


          foreach $File(@ARGV){

          open(FUT,"<$File") or die "Couldnt open $File $!";



          while(<FUT>){
          chomp;
          if(/^\s*$/){
          next;
          }
          if($Value=~ /[LH]/){
          if(/(\S+)\s+PIN\?\s(L|H)/){
          if($Value =~ /$2/){
          print "\nOh yeah $1 matched";
          }else{
          print "\nError $1 does NOT match in file $File!";
          }
          }else{

          chop($Value);
          redo;
          }
          next;
          }

          if(/PIN_(L|H)/){
          if($1 eq 'H'){
          $Value = 'H';
          next;

          }elsif($1 eq 'L'){
          $Value = 'L';
          next;

          }else{

          print "\nError in code."; #Should never arrive here
          }
          }
          }


          close(FUT);

          }
        • Charles K. Clarkson
          ... At this point $1 and $2 are defined. ... At this point $1 and $2 are undefined. Because of the last match was successful and didn t contain parenthesis.
          Message 4 of 4 , May 1, 2003
          • 0 Attachment
            Electron One <electron1@...> wrote:
            : while(<FUT>){
            : chomp;
            : if(/^\s*$/){
            : next;
            : }
            : if($Value=~ /[LH]/){
            : if(/(\S+)\s+PIN\?\s(L|H)/){

            At this point $1 and $2 are defined.

            : if($Value =~ /$2/){
            : print "\nOh yeah $1 matched";

            At this point $1 and $2 are undefined. Because
            of the last match was successful and didn't contain
            parenthesis.

            : }else{
            : print "\nError $1 does NOT match in file $File!";

            At this point $1 and $2 are defined. Because of
            the last match was unsuccessful.

            : }
            : } else {


            HTH,

            Charles K. Clarkson
            --
            Head Bottle Washer,
            Clarkson Energy Homes, Inc.
            Mobile Home Specialists
            254 968-8328
          Your message has been successfully submitted and would be delivered to recipients shortly.