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

Here Like Document

Discussion in 'T&T - Miscellaneous' started by Joe Caverly, Nov 5, 2009.

  1. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    658
    Likes Received:
    8
    I have become used to using the Here Document feature of Ruby, for small amounts of text, mainly for addresses. While TCC has the "Here-Document" and "Here-String" redirection, I have developed some methods that others might find useful.

    First, I create an environment variable to store the Here Like Document;

    Code:
    set jlc=Line 1^r^nLine 2^r^nLine 3
    Note the ^r^n sequence. These are the escape character codes for carriage return and line feed. If you echo the newly created environment variable;

    Code:
    C>echo %jlc
    Line 1
    Line 2
    Line 3
    You will get three lines of text, each one on their own line.

    Further, using the @words function, we can verify that there are indeed three lines (or words) in the environment variable;

    Code:
    C>echo %@words["^r^n",%jlc]
    3
    To extract each line (or word), use the @word function;

    Code:
    C>echo %@word["^r^n",0,%jlc]
    Line 1
    
    C>echo %@word["^r^n",1,%jlc]
    Line 2
    
    C>echo %@word["^r^n",2,%jlc]
    Line 3
    Now, let's suppose that you keep an address file as follows;

    Code:
    JP Software^r^nP.O. Box 328^r^nChestertown MD 21620 USA^r^nRecord %kount
    PowerBASIC Inc.^r^n2061 Englewood Road^r^nEnglewood FL 34223 USA^r^nRecord %kount
    Microsoft Corporation^r^nPO Box 97017^r^nRedmond WA USA^r^nRecord %kount
    You can access each complete address as follows;

    Code:
    @setlocal
    @echo off
    set kount=1
    do TheAddress in @addresses.txt
      echo %TheAddress
      echo.
      set kount=%@inc[%kount]
    enddo
    endlocal
    which produces the following output;

    Code:
    JP Software
    P.O. Box 328
    Chestertown MD 21620 USA
    Record 1
    
    PowerBASIC Inc.
    2061 Englewood Road
    Englewood FL 34223 USA
    Record 2
    
    Microsoft Corporation
    PO Box 97017
    Redmond WA USA
    Record 3
    Note the nonsense of the "Record %kount" in each address. This was simply an example of how you can place an environment variable in each record, and manipulate the environment variable from the batch file.

    For more information on Here Document in TCC, lookup Redirection in the Take Command Help file, at the bottom of the Redirection page.

    Joe
     

Share This Page