in reply to Use of uninitialized value $cui1 in print

You have given us very little to work on. you need to include much more information. Fix the above code to look like this

######################################## print 'size new:'.scalar(@new)."\n"; print 'n_size :'.$n_size."\n"; print 'new :'.join('|',@new)."\n"; ######################################## for(my $i=0;$i<$n_size;$i++){ my @w= split(/,/ , $new[$i]); ######################################## print 'i :'.$i."\n"; print 'size w :'.scalar(@w)."\n"; print 'w :'.join('|',@w)."\n"; ######################################## $w[0]=~s/\'//; #pre-process to remove ' from text $w[0]=~s/\'//; as @w='word1' 'word2' $w[1]=~s/\'//; $w[1]=~s/\'//; ######################################## print 'w[0] :'.$w[0]."\n"; print 'w[1] :'.$w[1]."\n"; print 'size w :'.scalar(@w)."\n"; ######################################## my $t1 = "$w[0]"; #$w[0]=word1 without single quotes my $t2 = "$w[1]"; #$w[1]=word2 ######################################## print 't1 :'.$t1."\n"; print 't2 :'.$t2."\n"; ######################################## # print $t1,$t2,"__________"; #working my $cu1 = $umls->getConceptList($t1); #calling function from umls +::similarity #ERRRO 1 as mentioned ######################################## print 'raw cu1:'.$cu1."\n"; print 'size cu1:'.scalar(@{$cu1})."\n"; print 'cu1 :'.join('|',@{$cu1})."\n"; ######################################## my $cui1 =pop @{$cu1}; ######################################## print 'new cu1:'.$cu1."\n"; ######################################## my $cu2 = $umls->getConceptList($t2);***error ######################################## print 'raw cu2:'.$cu2."\n"; print 'size cu2:'.scalar(@{$cu2})."\n"; print 'cu2 :'.join('|',@{$cu2})."\n"; ######################################## my $cui2 = pop @{$cu2}; ######################################## print 'new cu2:'.$cu2."\n"; ######################################## # print $cui1; # ****ERROR2 unintialized $cui1 my $lvalue = $lch->getRelatedness($cui1, $cui2); my $value = $path->getRelatedness($cui1, $cui2);
Then run it and post the output. Then someone may be able to help you.

Replies are listed 'Best First'.
Re^2: Use of uninitialized value $cui1 in print
by AnomalousMonk (Archbishop) on Mar 03, 2017 at 05:38 UTC
    ######################################## print 'raw cu1:'.$cu1."\n"; print 'size cu1:'.scalar(@{$cu1})."\n"; print 'cu1 :'.join('|',@{$cu1})."\n"; ########################################

    Raksha Jalan: Rather than using print statements in this way, I would recommend the use of something like Data::Dumper (which is core). It will IMHO be much more informative about what the variable (e.g., $cu1) really is, and will avoid the generation of a bunch more warnings if the variable is undefined.

    c:\@Work\Perl\monks>perl -wMstrict -le "use Data::Dumper; ;; my $x; print Dumper $x; ;; $x = []; print Dumper $x; ;; $x = [ 'hi', 'there' ]; print Dumper $x; " $VAR1 = undef; $VAR1 = []; $VAR1 = [ 'hi', 'there' ];
    BTW: I prefer the Data::Dump module, but it isn't core.


    Give a man a fish:  <%-{-{-{-<

Re^2: Use of uninitialized value $cui1 in print
by Raksha Jalan (Initiate) on Mar 03, 2017 at 09:50 UTC

    Thanks for reply. surprisedly value of $cui. raw $cui1 are not as expected AS it uniq ids not hash.

    here is the o/p after running above: i :405 size w :2 w : 'severe'| 'sunburn' w[0] : severe w[1] : sunburn size w :2 t1 : severe t2 : sunburn raw cu1:ARRAY(0x1dcf698) size cu1:0 cu1 : new cu1:ARRAY(0x1dcf698) raw cu2:ARRAY(0x1dcf6e0) size cu2:0 cu2 : new cu2:ARRAY(0x1dcf6e0)

      The strings in the  @w array seem to have whitespace before the first single-quote. Any leading whitespace will remain after the single-quotes are deleted from the string. Is this whitespace expected? Use of
          print Dumper \@w;
      would make any leading (or trailing) whitespace obvious.

      BTW: All single-quotes could be deleted from a string in a single
          $w[0]=~s/'//g;
      statement. Please see perlre, perlretut and perlrequick, and Regexp Quote-Like Operators in perlop for s///g. All single-quotes could be deleted from every string in an array with
          s/'//g for @w;
      (but this still leaves any whitespace untouched).


      Give a man a fish:  <%-{-{-{-<

      Ah, the joys of debuging by proxy. it seems i missed something in the debug statements and print 'new  cu1:'.$cu1."\n"; should have been print 'cui1    :'.$cui1."\n"; and print 'new  cu2:'.$cu2."\n"; should have been print 'cui2    :'.$cui2."\n";

      but this simple exercise has located the problem anyway, in that on i=405 the cu1/cu2 arrays are empty. that means the pops return undef and hence your error. is there anything different about 405? as noted by AnomalousMonk the strings in @w have leading spaces, is that true only on 405? Maybe that is the problem and needs to be fixed somehow, in @new or by regexp maybe.

      to workaround this for now you could change to

      unless (scalar(@{$cu1})) {print "cu1 is empty\n"; next} my $cui1 =pop @{$cu1}; ######################################## print 'cui1 :'.$cui1."\n"; ######################################## my $cu2 = $umls->getConceptList($t2);***error ######################################## print 'raw cu2:'.$cu2."\n"; print 'size cu2:'.scalar(@{$cu2})."\n"; print 'cu2 :'.join('|',@{$cu2})."\n"; ######################################## unless (scalar(@{$cu2})) {print "cu2 is empty\n"; next} my $cui2 = pop @{$cu2}; ######################################## print 'cui2 :'.$cui2."\n"; ########################################
      Notice how it aborts the rest of the loop if either of the arrays are empty. Notice it also includes the updated debug statements. Notice you may want to expand the output printed if they are empty