Loading ...
Sorry, an error occurred while loading the content.
 

Re: [Clip] Perl clips - what variable holds selection

Expand Messages
  • Wayne VanWeerthuizen
    ... Standard Input. ... Perl doesn t care how many lines it is. It is just standard input. ... Neither, it is treated as a stream. You have to read the data
    Message 1 of 1 , Jul 1, 2000
      "Piotr Bienkowski" <syntax@...> wrote:
      >1. Through what variable is Perl referring to the selected text or
      >whole document? One of Perl's special variables? WHich? Or is the
      >text gotten from standard input? Or can I mix languages here and
      >use a Clip variable in a Perl script?

      Standard Input.

      >2. Now if the selection contains just one line (or less), does
      >Perl treat it as a string?

      Perl doesn't care how many lines it is. It is just standard input.

      >3. If the selection (or whole document) contains many lines, is it
      >treated as an array of strings or one big string by Perl?

      Neither, it is treated as a stream. You have to read the data
      from the stream before you can use it. But that is very easy
      to do using the <> operator.


      To read it one line at a time: while (<>) { # Line is now in $_

      [This is usually the best approach. It does not allocate a lot
      of memory at one time.]


      To read it into an array use: @ArrayName = <>;

      [Can use a lot of memory, but sometimes this is the better method.]


      To read it into one variable use: $Variable = join ( "", <> );

      [This may be useful on rare occasion, but is not often recommended.
      Note that a large temporary array may be created during this step.]



      >Been there, done that, anyone?

      Yes. I think Perl is actually easier to program in than NoteTab's
      clip language. And perl is much faster and more resource efficient.
      For the things that could be done in either, I would recommend Perl.
      This applies mainly to making sophisticated changes to documents.
      There are many other tasks that only the clip language can
      reasonably accomplish, and vice-versa.

      If you have not downloaded NoteAwk from my webpage, you should. It
      has some nice clips to facilitate using Perl from within NoteTab.
      See http://landru.myhome.net/wayne/notetab.html

      It has been a long time, but I still am planning to release an
      updated versions eventually.







      --
      Wayne M. VanWeerthuizen
      Homepage: http://landru.myhome.net/wayne
    Your message has been successfully submitted and would be delivered to recipients shortly.