1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Here documents redirection

Discussion in 'Suggestions' started by jmcm, Aug 30, 2010.

  1. jmcm

    Joined:
    Jun 11, 2008
    Messages:
    26
    Likes Received:
    0
    I recently tried (unsuccessfully) to create a "here document" with
    redirection (ala perl) as per example below:

    [example]
    odbc %irisdb %sql1 | tee con | ^
    for %li in (@con:) echo <<-ETX1 >> clip:
    INSERT INTO branch (asset, brnch, customer, external, internal,
    xtended)
    VALUES (%@field[0,%li], %@field[1,%li], %@field[2,%li],

    %@if[%@isalnum[%@field[3,%li]],%@field[3,%li],null],

    %@if[%@isalnum[%@field[4,%li]],%@field[4,%li],null],
    %@if[%@isalnum[%@field[5,%li]],%@field[5,%li],null]);
    ETX1
    [/example] -- excuse the line wrapping

    Of course TIMTOWTDI and I achieved something similar, but the method
    depicted above would have been prettier.

    I would like to suggest this method of redirection for consideration as
    an enhancement to the "here document" feature. I hope others might find
    this enhancement pretty useful too.

    John

    --
    Regards
    John McMahon
    lists@jspect.fastmail.fm
     
  2. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,178
    Likes Received:
    11
    You can do something similar to that already.

    (for %li in (@con) do echo %li) << ETX1
    INSERT INTO branch (asset, brnch, customer, external, internal, xtended)
    VALUES (%@field[0,%li], %@field[1,%li], %@field[2,%li],
    %@if[%@isalnum[%@field[3,%li]],%@field[3,%li],null],
    %@if[%@isalnum[%@field[4,%li]],%@field[4,%li],null],
    %@if[%@isalnum[%@field[5,%li]],%@field[5,%li],null]);
    ETX1

    Or equivilently in TC12:

    (do li in @con (echo %li)) << ETX1
    ...
    ETX1

    Looking at your code, I see that you expected the input to come from stdin
    and to use the entire here-document as the target of the ECHO. So my
    example doesn't really apply...

    -Scott

    jmcm <> wrote on 08/30/2010 10:23:22 PM:


     
  3. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,178
    Likes Received:
    11
    This does work however:

    odbc %irisdb %sql1 | tee con | for %li in (@con) do (
    echo INSERT INTO branch (asset, brnch, customer, external, internal,
    xtended) ^
    VALUES (%@field[0,%li], %@field[1,%li], %@field[2,%li], ^
    %@if[%@isalnum[%@field[3,%li]],%@field[3,%li],null], ^
    %@if[%@isalnum[%@field[4,%li]],%@field[4,%li],null], ^
    %@if[%@isalnum[%@field[5,%li]],%@field[5,%li],null]);
    ) >> clip:

    -Scott

    samintz <> wrote on 08/31/2010 11:46:03 AM:


    stdin

    as

    find

     
  4. jmcm

    Joined:
    Jun 11, 2008
    Messages:
    26
    Likes Received:
    0
    Thanks for responding Scott. That last example was exactly how I did it.
    I was not looking for a solution, I was proposing an enhancement to
    "here documents" in the TCC environment to do something that I thought
    could be done in another environment (but can't verify right now)
    because I thought it would be neat.

    TIMTOWTDI (There Is More Than One Way To Do It).

    John

    On 1/09/2010 4:45 AM, samintz wrote:

    --
    Regards
    John McMahon
    lists@jspect.fastmail.fm
     

Share This Page