Je55eah has asked for the wisdom of the Perl Monks concerning the following question:

I feel stupid asking this but, how can I make this here doc work? I have looked at http://perldoc.perl.org/perlfaq4.html#Why-don't-my-%3c%3cHERE-documents-work%3f

$author = 'Jesse'; $date = scalar localtime; $document = <<ENDHEREDOC; Hello $author. The time is: $date ENDHEREDOC print $document;

and the result is:

Can't find string terminator "ENDHEREDOC" anywhere before EOF at test. +pl line 3. Press any key to continue . . .

As an aside, is there a nice and simple way to get the current local date time as YYYY-MM-DD-HH:MM:SS ? All of the examples I was finding were multistep processes involving adding numbers to 1900 and so on. I threw this scalar thing in because i wondered what it would do, but the HEREDOC is holding things up, so I havn't seen the result yet. Thanks,

Replies are listed 'Best First'.
Re: Please help me with this Heredoc
by toolic (Bishop) on Jun 18, 2012 at 02:20 UTC
    Use diagnostics. From perldiag
    If you're getting this error from a here-document, you may have included unseen whitespace before or after your closing tag or there may not be a linebreak after it. A good programmer's editor will have a way to help you find these characters (or lack of characters).

      I don't know how, but it is working now. Since I am just getting started with Perl I am satisfied unless it breaks again. The next paragraph is probably useless to you. Thanks perldiag and andrew.

      I played around with splain and I saw some strange stuff where the first characters of the second line were being replaced with the heredoc delimiter string. I was about to post some copies of those results on here, so I changed the code back to what I posted earlier for the sake of consistency. Now it is magically working. Padre did crash when I was doing this, so I think that Padre somehow corrupted the file (??) and the corruption was invisible to me but it was manifesting in the results from padre's run button and the command line execution.

Re: Please help me with this Heredoc
by afresh1 (Hermit) on Jun 18, 2012 at 02:05 UTC

    I downloaded the first version that you posted and it "worked for me" so I am unsure why it isn't working for you.

    $ perl 976706.pl Hello Jesse. The time is: Sun Jun 17 18:56:19 2012

    For the printing the date in nearly any format you want you can use the DateTime module.

    $ perl -MDateTime -E 'say DateTime->now->strftime("%Y-%m-%d %H:%M:%S") +' 2012-06-18 01:58:52
    l8rZ,
    --
    andrew
      Andrew, Thank you. Somehow I need to fix dwimperl before I have even used it. Any ideas short of uninstall reinstall?
Re: Please help me with this Heredoc
by Je55eah (Novice) on Jun 18, 2012 at 01:44 UTC

    I have checked for extra whitespace atter the closing ENDHEREDOC. Even this fails.

    # Begin $author = 'Jesse'; #my $date = scalar localtime; print <<"ENDHEREDOC"; Hello. The time is: ENDHEREDOC # End
Re: [SOLVEDish] Please help me with this Heredoc
by Anonymous Monk on Jun 19, 2012 at 00:37 UTC
    Using POSIX 'strftime', you may print today's date. POSIX is core Perl since version 5.

    use POSIX qw/ strftime /; my $date = strftime "%Y-%m-%d %H:%M:%S", localtime;