Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Uninitialized value in concatenation

by eiglesias (Initiate)
on Jan 25, 2008 at 16:29 UTC ( #664309=perlquestion: print w/ replies, xml ) Need Help??
eiglesias has asked for the wisdom of the Perl Monks concerning the following question:

I am having problems with what I thought was a pretty simple script. The errors I get are
Use of uninitialized value in concatenation (.) or string at ./fund.pl + line 25, <STDIN> line 1. Use of uninitialized value in concatenation (.) or string at ./fund.pl + line 28, <STDIN> line 1. Use of uninitialized value in concatenation (.) or string at ./fund.pl + line 32, <STDIN> line 1. Use of uninitialized value in concatenation (.) or string at ./fund.pl + line 32, <STDIN> line 1. Use of uninitialized value in transliteration (tr///) at ./fund.pl lin +e 47, <STDIN> line 9535. Use of uninitialized value in concatenation (.) or string at ./fund.pl + line 48, <STDIN> line 9535.
I am unsure what is causing this error and any help would be appreciated. The script is below.
#!/usr/bin/perl -w ###### usage: cat inputfile | abiglobal.pl $i=0; while ($_ = <STDIN>) { if(/(FUND ACTIVITY REPORT)/ ) { $input=$_; chop($input); $fundcode=substr($input,0,5); $fundcode=~ s/ //g; $input=~ tr/\"//; $input=~ tr/\'//; # $input=~ tr/,/\t/; $input=~s/REPORT,/REPORT /g; $input=~s/ / /g; @in=split(/ /,$input); # @fund=$in[0]; if($i=="0"){ $final=$in[3].".html"; open (OUT,">>body.txt") || die "I am not able to write to file"; open (HEAD,">>head.txt") || die "not able to open temp header"; print HEAD "<HTML><HEAD><TITLE>Fund Activity Report</TITLE></HEAD> +<BODY><TABLE border=1><tr><td><strong>Fund Activity Reports: $in[3] +</strong></td></tr><TR><td valign='top'><a href='#$fundcode'>$fundcod +e</a>&nbsp;\n"; $i=99; } print HEAD "<a href='#$fundcode'>$fundcode</a>&nbsp;\n"; print OUT "<strong><a name='$fundcode'>Fund: <u>$in[0]</u> </a>Fun +dInfo: <u>$in[1] $in[2]</u></strong><br>\n"; } else { print OUT "<pre>$_</pre>\n"; } } #### end while stdin print HEAD "</td></tr></table><br><br>\n"; print OUT "</body></html>\n +"; close OUT; close HEAD; #$outfile=~tr/ /_/; $outfile=~tr/,/_/; print "$outfile\n"; system "cat head.txt body.txt >>/home/fundlist/test/$final"; system "r +m head.txt"; system "rm body.txt"; opendir(DIR, "./public_html"); open (OUT,">/home/fundlist/test/index.html") || die "I am not able + to write to file"; print OUT ("<HTML><HEAD><TITLE>Fund List Director +y</TITLE></HEAD><BODY>\n"); print OUT ("<h4>Directory Listing</h4>\n"); while($file = readdir(DIR) ) { print OUT ("<A HREF=\"$file\">$file<br>\n"); } print OUT ("</body></html>\n"); closedir(DIR); close (OUT);

Comment on Uninitialized value in concatenation
Select or Download Code
Re: Uninitialized value in concatenation
by moritz (Cardinal) on Jan 25, 2008 at 16:34 UTC
    It means that some your variables, for example $in[3], don't contain any values.

    It also means that some variables don't contain the values that you think they should - so check their values with print statements, the debugger, Data::Dumper or Smart::Comments.

    And these are not errors (fatal), but warnings (nonfatal).

Re: Uninitialized value in concatenation
by toolic (Chancellor) on Jan 25, 2008 at 16:42 UTC
    Using use diagnostics; in addition to use warnings; will give you more information that is sometimes helpful in debugging your problem. It is also a good practice to use strict;.

    Update: something unrelated to consider: you keep opening your OUT and HEAD filehandles within your first while loop, but you do not close them until you are out of the loop.

Re: Uninitialized value in concatenation
by olus (Curate) on Jan 25, 2008 at 16:48 UTC
    I copied your script into a new file and validated its syntax
    perl -c z3.pl z3.pl syntax OK
    But then, I added use strict; on line 3 and did the same procedure
    perl -c z3.pl Global symbol "$i" requires explicit package name at z3.pl line 6. Global symbol "$input" requires explicit package name at z3.pl line 11 +. Global symbol "$input" requires explicit package name at z3.pl line 12 +. Global symbol "$fundcode" requires explicit package name at z3.pl line + 13. Global symbol "$input" requires explicit package name at z3.pl line 13 +. Global symbol "$fundcode" requires explicit package name at z3.pl line + 14. Global symbol "$input" requires explicit package name at z3.pl line 15 +. Global symbol "$input" requires explicit package name at z3.pl line 16 +. Global symbol "$input" requires explicit package name at z3.pl line 18 +. Global symbol "$input" requires explicit package name at z3.pl line 19 +. Global symbol "@in" requires explicit package name at z3.pl line 20. Global symbol "$input" requires explicit package name at z3.pl line 20 +. Global symbol "$i" requires explicit package name at z3.pl line 24. Global symbol "$final" requires explicit package name at z3.pl line 25 +. Global symbol "@in" requires explicit package name at z3.pl line 25. Global symbol "@in" requires explicit package name at z3.pl line 28. Global symbol "$fundcode" requires explicit package name at z3.pl line + 28. Global symbol "$fundcode" requires explicit package name at z3.pl line + 28. Global symbol "$i" requires explicit package name at z3.pl line 29. Global symbol "$fundcode" requires explicit package name at z3.pl line + 31. Global symbol "$fundcode" requires explicit package name at z3.pl line + 31. Global symbol "$fundcode" requires explicit package name at z3.pl line + 32. Global symbol "@in" requires explicit package name at z3.pl line 32. Global symbol "@in" requires explicit package name at z3.pl line 32. Global symbol "@in" requires explicit package name at z3.pl line 32. Global symbol "$outfile" requires explicit package name at z3.pl line +44. Global symbol "$outfile" requires explicit package name at z3.pl line +45. Global symbol "$final" requires explicit package name at z3.pl line 46 +. Global symbol "$file" requires explicit package name at z3.pl line 52. Global symbol "$file" requires explicit package name at z3.pl line 54. Global symbol "$file" requires explicit package name at z3.pl line 54. z3.pl had compilation errors.
    And that matches line numbers (and a few more) where you are getting those messages.

    No matter how simple the script may be use strict is not to be avoided and can save you some headaches.
Re: Uninitialized value in concatenation
by jwkrahn (Monsignor) on Jan 25, 2008 at 18:54 UTC
    $input=~ tr/\"//; $input=~ tr/\'//;

    You are replacing the " character with itself and the ' character with itself. If you want to delete characters you have to use the /d option:

    $input=~ tr/"//d; $input=~ tr/'//d;
Re: Uninitialized value in concatenation
by FunkyMonk (Canon) on Jan 25, 2008 at 22:21 UTC
    If you can, you might want to install the latest release of Perl, perl 5.10. It will tell you which variable isn't initialised:
    $ perl -Mstrict -we 'my $x; print $x' Use of uninitialized value $x in print at -e line 1.

    You should be using use strict too.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (16)
As of 2014-07-31 14:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (249 votes), past polls