in reply to Re: Use of uninitialized value $cui1 in print
in thread Use of uninitialized value $cui1 in print

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)

Replies are listed 'Best First'.
Re^3: Use of uninitialized value $cui1 in print
by AnomalousMonk (Archbishop) on Mar 03, 2017 at 10:29 UTC

    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:  <%-{-{-{-<

Re^3: Use of uninitialized value $cui1 in print
by huck (Prior) on Mar 03, 2017 at 14:53 UTC

    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