Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Here document construct problem

by hok_si_la (Curate)
on Feb 17, 2005 at 20:23 UTC ( #432074=perlquestion: print w/ replies, xml ) Need Help??
hok_si_la has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks,

I recently ran into a problem with one of my scripts. After chatting with Bart it on the CB I was convinced that I should use qq(..) instead of the here document. My curiosity has the better of me though. I am still trying to figure out what went wrong in my original script. The script itself it really long, but can be viewed at my scratchpad. hok_si_la's scratchpad
In Summation,
########### Works ############## print <<END_OF_PRINT; <blahtag>blah blah $blah</blahtag> <blahtag>blah blah $blah</blahtag> #END_OF_PRINT #&printOwner($data{owner1}); #&printOwner($data{owner2}); #&printOwner($data{owner3}); #print <<END_OF_PRINT; <blahtag>blah blah $blah</blahtag> <blahtag>blah blah $blah</blahtag> END_OF_PRINT ######## Doesn't Work ########## print <<END_OF_PRINT; <blahtag>blah blah $blah</blahtag> <blahtag>blah blah $blah</blahtag> END_OF_PRINT #&printOwner($data{owner1}); #&printOwner($data{owner2}); #&printOwner($data{owner3}); print <<END_OF_PRINT; <blahtag>blah blah $blah</blahtag> <blahtag>blah blah $blah</blahtag> END_OF_PRINT
I am receiving the following warning:

Use of uninitialized value in concatenation (.) or string at D:\wwwroot\NewServer\test\scripts\Gnewserver.pl line 349. Use of uninitialized value in concatenation (.) or string at D:\wwwroot\NewServer\test\scripts\Gnewserver.pl line 349. Use of uninitialized value in concatenation (.) or string at D:\wwwroot\NewServer\test\scripts\Gnewserver.pl line 349. Use of uninitialized value in concatenation (.) or string at D:\wwwroot\NewServer\test\scripts\Gnewserver.pl line 349. Use of uninitialized value in concatenation (.) or string at D:\wwwroot\NewServer\test\scripts\Gnewserver.pl line 349. Use of uninitialized value in concatenation (.) or string at D:\wwwroot\NewServer\test\scripts\Gnewserver.pl line 349. Use of uninitialized value in concatenation (.) or string at D:\wwwroot\NewServer\test\scripts\Gnewserver.pl line 349. Use of uninitialized value in concatenation (.) or string at D:\wwwroot\NewServer\test\scripts\Gnewserver.pl line 349. Use of uninitialized value in concatenation (.) or string at D:\wwwroot\NewServer\test\scripts\Gnewserver.pl line 349. Use of uninitialized value in concatenation (.) or string at D:\wwwroot\NewServer\test\scripts\Gnewserver.pl line 349. Use of uninitialized value in concatenation (.) or string at D:\wwwroot\NewServer\test\scripts\Gnewserver.pl line 349. Use of uninitialized value in concatenation (.) or string at D:\wwwroot\NewServer\test\scripts\Gnewserver.pl line 349. Use of uninitialized value in concatenation (.) or string at D:\wwwroot\NewServer\test\scripts\Gnewserver.pl line 349. Use of uninitialized value in concatenation (.) or string at D:\wwwroot\NewServer\test\scripts\Gnewserver.pl line 349. Operating System: Windows 2003 Server (Standard

The warning is placed in various locations depending on the initial query.

Sorry in advance for writing a book, but I am very curious about the problem.

Your help would be appreciated greatly,
hok_si_la

UPDATE:I figured out one huge prob. I had a lexically global defined %data for my main, and the subroutine printowners defined a %data within its scope. That could not be good.

Comment on Here document construct problem
Download Code
Re: Here document construct problem
by artist (Parson) on Feb 17, 2005 at 20:34 UTC
    "Original Script" has an extra space character at the end (after END_OF_PRINT). Remove that character and it should work fine.
      Artist,

      I removed the trailing spaces, and I am still getting the warning. I will update my scratchpad with the new code.

      hok_si_la

        Can you run this code (via the shell/Command Prompt/Run)

        perl -nle "print qq(Check line: $.), if (m/print <<ENDOFHTML;\s+$/ or (m/^(\s*)ENDOFHTML(\s*)$/ and ($1 or $2)))" filename

Re: Here document construct problem
by kutsu (Priest) on Feb 17, 2005 at 20:37 UTC

    As I pointed out in the CB both the here docs and qq or q work for me; so the error is either somewhere else or you forgot to end a HERE doc somewhere. my test case:

    Judging by the amount of HTML your printing using HERE docs in your code, you might want to look at HTML::Template. Which would allow you to seperate your HTML and perl code (which is much easier to debug and update).

    "Cogito cogito ergo cogito sum - I think that I think, therefore I think that I am." Ambrose Bierce

      I have actually already begun the tedius process of replacing the here document constructs with q() in all of my scripts. I was just wondering why in this particular script I was running into probs. With regard to your testing i can narrow the entire script down to just that block I showed before and the basic HTML tags and I still get warnings. I looked at the HTML::Template, and would surely use it if I could. I only have two weeks left on the project, and I need to get all 70 + scripts updated to DBI and CGI::simple first. I am currently in the process of adding "use strict" and "use warnings" to every script which is how I ran into this problem in the first place.

      Thanks for all your time,
      hok_si_la
Re: Here document construct problem
by Animator (Hermit) on Feb 17, 2005 at 20:41 UTC

    Are you sure $data is defined? and all elements in data? Have you tried dumping the %data-hash (using Data::Dumper)?

    The code in your scratchpad does not show the definition of %data...

      Animator,

      Data and all of its elements seem to be defined. The script spits them out as it should with the one exception being the table row that prints out the warnings, which actually changes from query to query. I have not tried data dumper yet. I can comment out the subroutine call altogether and still have issues, so that shouldn't be it. At this point I am not really one to say though so I will give it a try.

      hok_si_la
Re: Here document construct problem
by thedoe (Monk) on Feb 17, 2005 at 21:09 UTC

    What is the full source code? Just by using your scratchpad it is not possible to examine the line of code actually generating the warning.

    When using warnings, perl generates this warning when it tries to evaluate a variable that has not been previously defined. Try looking at line 349 in your code and what variables are being used in it. If there are multiple variables used, use the process of elimination to figure out which is causing your problem, then make sure to assign it the value you need.

    Update: Changed using strict to using warnings to correct mix-up.

      thedoe,

      Using strict doesn't cause the warnings. Usings warnings does. If I comment out "use warnings;" I have no prob. The line that the warning is referring to is the middle END_OF_PRINT from the block of code that I posted. This block is encased by "&*&*&*&*&*&*&" in my scratchpad. I will comment the line itself.

      hok_si_la

        What happens if:

        END_OF_PRINT #&printOwner($data{owner1}); #&printOwner($data{owner2}); #&printOwner($data{owner3}); print <<END_OF_PRINT; </TH> </TR> END_OF_PRINT

        is changed to:

        #END_OF_PRINT #&printOwner($data{owner1}); #&printOwner($data{owner2}); #&printOwner($data{owner3}); #print <<END_OF_PRINT; </TH> </TR>
        and picked up by the END_OF_PRINT that occurs after <html> ?

        Update: Ok. Just checking for any weirdness in slight deviations from what you posted above. Ignore my comments below this reply, for they were added in error.

        /renz.
        "This is the Mark-man, safe and sure,
        Who still is right, and prayes to be so still."
        --George Herbert, Constancie.

        I apologize for my previous mixup of use strict and use warnings.

        As for where the warnings are coming from, they are being generated by variables within the here document starting at line 349. Any variables inside which have not been previously assigned will give you this warning and report line 349. This includes any keys in the data hash which have not been previously assigned, even if the data hash has been created.

        A good way to debug it would be using Data::Dumper as previously suggested for the data hash and manually inspecting any other variables used within that here document.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2014-12-28 05:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (178 votes), past polls