Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

here-doc not working? 2

Status
Not open for further replies.

feherke

Programmer
Aug 5, 2002
9,541
RO
Hi

man perlop said:
The terminating string must appear by itself (unquoted and with no surrounding whitespace) on the terminating line.
Perl:
    [b]my[/b] [navy]$sql[/navy] [teal]=[/teal] [teal]<<[/teal]ENDSQL[teal];[/teal]
ENDSQL
[gray]# ^-- no leading space[/gray]

[gray]# or[/gray]

[gray]#                  v-- same amount of spaces here ...[/gray]
    [b]my[/b] [navy]$sql[/navy] [teal]=[/teal] [teal]<<[/teal][green][i]'    ENDSQL'[/i][/green][teal];[/teal]
    ENDSQL
[gray]# ^-- ... and here[/gray]

Feherke.
 
Thanks Feherke,

1st time I've used it so I'm not suprised I had problems.

Makes code indenting a nightmare or as you say , I'll have to add the same amount of whitespace, however I can't use the quote as you have it as I read it won't interpolate if you do that.

so it's going to have to be ugly, bad practice, non-indented code!

-----------------------------------

Update -> still getting same error with...
Code:
    # build SQL    
    my $sql = <<ENDSQL;
        SELECT *
        FROM CASE_DETAILS 
        JOIN $mort_table ON CASE_DETAILS.CaseId = $mort_table.CaseId 
        JOIN ADVISER ON CASE_DETAILS.AdviserIndexId = ADVISER.IndexId 
        WHERE CASE_DETAILS.CaseId = $_[0]{'CaseId'} AND CASE_DETAILS.CompanyId = $_[0]{'CompanyId'}
ENDSQL

i made sure the last line had no whitespace on the end and the 'ENDSQL' is far left with no space or indentation, but still getting same error?

I gave up and used concatenation instead!

Code:
    # build SQL    
    my $sql = "SELECT * FROM CASE_DETAILS" .
        " JOIN $mort_table ON CASE_DETAILS.CaseId = $mort_table.CaseId" .
        " JOIN ADVISER ON CASE_DETAILS.AdviserIndexId = ADVISER.IndexId" .
        " WHERE CASE_DETAILS.CaseId = $_[0]{'CaseId'} AND CASE_DETAILS.CompanyId = $_[0]{'CompanyId'}"

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
damn, there was a trailing white space on the ENDSQL line i hadn't noticed.

bit anal the old here-doc isn't it!

Cheers Feherke!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Hi

1DMF said:
I can't use the quote as you have it as I read it won't interpolate if you do that.
Oops, missed that. Just use double quote ( " ) instead :
Perl:
    [b]my[/b] [navy]$sql[/navy] [teal]=[/teal] [teal]<<[/teal][green][i]"    ENDSQL"[/i][/green][teal];[/teal]
    ENDSQL


Feherke.
 
i was wondering if double quote was OK, but the info I found regarding here-doc just showed it not quoted or use single quote for no interpolation.

It's working fine now the trailing whitespace has been culled.

Thanks again Feherke, it makes the SQL code much more readable using this method.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Using quotes around a heredoc is how you specify if it should be interpolated or not. By default heredoc's are interpolated so double quotes are assumed.

Most people don't necessarily know what is default though, so it's good practice to always use double quotes around your heredocs.

- Miller
 
Thanks Miller - I shall cordially add them.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top