in reply to Embedding fuction output

You can use the @{[func(@args)]} construct, it's ugly but it works:

print <<EOPAGE yarri, yarri, @{[CONF::botnav()]} yarra... EOPAGE

I have never really dug the why of this idiom, the best explanation I can come up with is: [func(@args)] tells Perl that you want to put the result of the function in an anonymous array, and the @{} bit gets the content of that array in a way that is expanded in double-quoted strings (by using EOPAGE without any quotes it defaults to <<"EOPAGE" which treates the following string as double-quoted, nothing would get expanded if you used <<'EOPAGE').

Now whether this increases clarity or adds to the general confusion... you'll have to decide for yourself!

Replies are listed 'Best First'.
Re: Re: Embedding fuction output
by Hofmator (Curate) on Jun 11, 2001 at 18:10 UTC

    and just to add, if you need scalar context make it simply:

    @{[scalar func(@args)]}

    -- Hofmator

Re: Re: Embedding fuction output
by bwana147 (Pilgrim) on Jun 11, 2001 at 19:31 UTC

    "Now whether this increases clarity or adds to the general confusion..."
    Now that's a good question if you ask me. Be aware that the @{[]} construct allows you to stuff any code inside the square brackets, be it merely a function call or a loop or an ugly if..elsif..elsif..else sequence, or whatever. That's tempting but you're likely to end up with your whole program consisting of a print statement,one big here-document, and all the rest of it scattered here and there in the here-doc.

    I would definitely stay with the option of running the code beforehand to feed any local variable, and then use these variables within the here-docs. Or go a step further and use templating solutions like HTML::Template or the Template Toolkit.

    --bwana147