Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Perl ERROR for uninitiated value or string

by waytoperl (Acolyte)
on Nov 27, 2013 at 01:53 UTC ( #1064512=perlquestion: print w/ replies, xml ) Need Help??
waytoperl has asked for the wisdom of the Perl Monks concerning the following question:

Hi Masters,

I'm stuck at a code that gives ERROR! I'm not able to figure out why these error is reported. To my understanding I'm defining a local variable and assigning hash table values to my locally defined variable. Then I'm trying to print by adding these local variable to pre-defined array elements (DIN_SETUP_RISE[0] .... ). Please help me!!! Thanks.

Use of uninitialized value in concatenation (.) or string at gen_lib.p +l line 571 (#1) (W uninitialized) An undefined value was used as if it were alread +y defined. It was interpreted as a "" or a 0, but maybe it was a mi +stake. To suppress this warning assign a defined value to your variables. To help you figure out what was undefined, perl tells you what ope +ration you used the undefined value in. Note, however, that perl optimiz +es your program and the operation displayed in the warning may not necessa +rily appear literally in your program. For example, "that $foo" is usually optimized into "that " . $foo, and the warning will refer +to the concatenation (.) operator, even though there is no . in your program. Use of uninitialized value in concatenation (.) or string at gen_lib.p +l line 572 (#1) Use of uninitialized value in concatenation (.) or string at gen_lib.p +l line 573 (#1) Use of uninitialized value in concatenation (.) or string at gen_lib.p +l line 574 (#1)

Program were error occurs

foreach my $key (sort keys %hash) { #Assign $inc with hash value my $inc1 = @{$hash{$key}}[1]; my $inc2 = @{$hash{$key}}[2]; my $inc3 = @{$hash{$key}}[3]; my $inc4 = @{$hash{$key}}[4]; my $inc5 = @{$hash{$key}}[5]; my $inc6 = @{$hash{$key}}[6]; my $inc7 = @{$hash{$key}}[7]; my $inc8 = @{$hash{$key}}[8]; my $inc9 = @{$hash{$key}}[9]; my $inc10 = @{$hash{$key}}[10]; my $inc11 = @{$hash{$key}}[11]; my $inc12 = @{$hash{$key}}[12]; # Does current hash key value equal C_CLK_and_SCANCLK_L__I +N if ( @{$hash{$key}}[0] eq "C_CLK_and_SCANCLK_L__IN" ) { $count_C_CLK_and_SCANCLK_L__IN++; print $outfile1 "\"$DIN_SETUP_RISE_1[0] + $inc3, ",", +$DIN_SETUP_RISE_1[1] + $inc3, ",", $DIN_SETUP_RISE_1[2] + $inc3, \", +\n"; print $outfile1 "\"$DIN_SETUP_RISE_2[0] + $inc3, ",", +$DIN_SETUP_RISE_2[1] + $inc3, ",", $DIN_SETUP_RISE_2[2] + $inc3, \", +\n"; print $outfile1 "\"$DIN_SETUP_RISE_3[0] + $inc3, ",", +$DIN_SETUP_RISE_3[1] + $inc3, ",", $DIN_SETUP_RISE_3[2] + $inc3, \", +\n"; } }

Hash Table

$VAR1 = { 'KEY_NAME1' => [ 'VALUE1', '0.150', '0.900', '', '', '', '', '0.150', '0.900' ], 'KEY_NAME2' => [ 'VALUE2', '', '', '0.500', '0.500', '0.500', '0.500', '', '', '0.500', '0.500', '0.500', '0.500' ], };

Comment on Perl ERROR for uninitiated value or string
Select or Download Code
Re: Perl ERROR for uninitiated value or string
by Anonymous Monk on Nov 27, 2013 at 02:24 UTC

      Since I'm dumping $inc1 .... $inc12 to a text file, they values are read. Additional to these I've another function that reads data from a file and stores it in a array. After storing in array I'm printing these array. Here comes the problem, script is not printing.

      Code I'm using to create a array is:

      while (<$infile_lib1>) { if ($_ =~ /values \( \/ /) { $line = <$infile_lib1>; @DIN_SETUP_RISE_1 = split /,/,$line; print "@DIN_SETUP_RISE_1 \n"; $line = <$infile_lib1>; @DIN_SETUP_RISE_2 = split /,/,$line; print "@DIN_SETUP_RISE_2 \n"; $line = <$infile_lib1>; @DIN_SETUP_RISE_3 = split /,/,$line; print "@DIN_SETUP_RISE_3 \n"; } }

      Input file have these values:

      values ( \ "0.1234567, 0.2345678, 0.3456789, 0.4567891, 0.56789123, 0 +.67891234, 0.78912345", \ "0.1234567, 0.2345678, 0.3456789, 0.4567891, 0.56789123, 0 +.67891234, 0.78912345", \ "0.1234567, 0.2345678, 0.3456789, 0.4567891, 0.56789123, 0 +.67891234, 0.78912345", \ "0.1234567, 0.2345678, 0.3456789, 0.4567891, 0.56789123, 0 +.67891234, 0.78912345", \ "0.1234567, 0.2345678, 0.3456789, 0.4567891, 0.56789123, 0 +.67891234, 0.78912345", \ "0.1234567, 0.2345678, 0.3456789, 0.4567891, 0.56789123, 0 +.67891234, 0.78912345", \ "0.1234567, 0.2345678, 0.3456789, 0.4567891, 0.56789123, 0 +.67891234, 0.78912345", \ );

      Some how I'm not able to create an list of array for each line read, split and assign to array. Perl does not report any error when I execute code, and array is not getting print. I've used all debug tools available, like strict, warnings, diagnostic...please help!!

        What is $line, where does that variable come from?
        use more ddumper
        #!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd pp /; my $samplefile = q{ values ( \ "0.1234567, 0.2345678, 0.3456789, 0.4567891, 0.56789123, 0 +.67891234, 0.78912345", \ "0.1234567, 0.2345678, 0.3456789, 0.4567891, 0.56789123, 0 +.67891234, 0.78912345", \ "0.1234567, 0.2345678, 0.3456789, 0.4567891, 0.56789123, 0 +.67891234, 0.78912345", \ "0.1234567, 0.2345678, 0.3456789, 0.4567891, 0.56789123, 0 +.67891234, 0.78912345", \ "0.1234567, 0.2345678, 0.3456789, 0.4567891, 0.56789123, 0 +.67891234, 0.78912345", \ "0.1234567, 0.2345678, 0.3456789, 0.4567891, 0.56789123, 0 +.67891234, 0.78912345", \ "0.1234567, 0.2345678, 0.3456789, 0.4567891, 0.56789123, 0 +.67891234, 0.78912345", \ ); }; my @DIN_SETUP_RISE_1; my @DIN_SETUP_RISE_2; my @DIN_SETUP_RISE_3; open my($infile_lib1), '<', \$samplefile; while (<$infile_lib1>) { if ($_ =~ /values \( \/ /) { my $line = <$infile_lib1>; @DIN_SETUP_RISE_1 = split /,/,$line; print "@DIN_SETUP_RISE_1 \n"; $line = <$infile_lib1>; @DIN_SETUP_RISE_2 = split /,/,$line; print "@DIN_SETUP_RISE_2 \n"; $line = <$infile_lib1>; @DIN_SETUP_RISE_3 = split /,/,$line; print "@DIN_SETUP_RISE_3 \n"; } else { dd( nomatch => $_ ); } } dd( DIN => \@DIN_SETUP_RISE_1, \@DIN_SETUP_RISE_2, \@DIN_SETUP_RISE_3 +); __END__ ("nomatch", "\n") ("nomatch", "values ( \\\n") ( "nomatch", " \"0.1234567, 0.2345678, 0.3456789, 0.4567891, 0.5678912 +3, 0.67891234, 0.78912345\", \\\n", ) ( "nomatch", " \"0.1234567, 0.2345678, 0.3456789, 0.4567891, 0.5678912 +3, 0.67891234, 0.78912345\", \\\n", ) ( "nomatch", " \"0.1234567, 0.2345678, 0.3456789, 0.4567891, 0.5678912 +3, 0.67891234, 0.78912345\", \\\n", ) ( "nomatch", " \"0.1234567, 0.2345678, 0.3456789, 0.4567891, 0.5678912 +3, 0.67891234, 0.78912345\", \\\n", ) ( "nomatch", " \"0.1234567, 0.2345678, 0.3456789, 0.4567891, 0.5678912 +3, 0.67891234, 0.78912345\", \\\n", ) ( "nomatch", " \"0.1234567, 0.2345678, 0.3456789, 0.4567891, 0.5678912 +3, 0.67891234, 0.78912345\", \\\n", ) ( "nomatch", " \"0.1234567, 0.2345678, 0.3456789, 0.4567891, 0.5678912 +3, 0.67891234, 0.78912345\", \\\n", ) ("nomatch", " );\n") ("DIN", [], [], [])
Re: Perl ERROR for uninitiated value or string
by kcott (Abbot) on Nov 27, 2013 at 08:04 UTC

    G'day waytoperl,

    To access an element in your hash of arrays, you should be using $hash{$key}[$i], not @{$hash{$key}}[$i]. See perldsc: HASHES OF ARRAYS.

    Your 12 my $incN = @{$hash{$key}}[N]; statements seem pointless: you only use $inc3 and there's no need for even that assignment as you already have the value in $hash{$key}[3] (see previous point).

    Your code indicates that you think all your arrays have (at least) 13 elements. Your "Hash Table" output shows this is not the case.

    Check the values you are using with the defined function to determine which is undefined. See your diagnostics output for why you would check for definedness.

    -- Ken

Re: Perl ERROR for uninitiated value or string
by marinersk (Chaplain) on Nov 27, 2013 at 13:23 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1064512]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2014-07-26 05:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls