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

Re: [Clip] text processing with a Perl script

Expand Messages
  • acumming@cwnet.com
    On Thu, 4 Aug 2005 16:59 , H Tao sent: [ . . ] ... (BTW, cc d to ntb-scripts since material herein is more so on topic at
    Message 1 of 1 , Aug 5, 2005
    • 0 Attachment
      On Thu, 4 Aug 2005 16:59 , H Tao <ht_ling@...> sent:
      [ . . ]
      >A friend of mine wrote a Perl script (KWIC) that can
      >do
      >concordancing (searching a word and displaying each
      >and every instances of its use in a
      >text).
      >
      >(http://www.corpus4u.com/forum_view.asp\?forum_id=38&view_id=688)
      >
      >I'd like to be able to call upon this script and use
      >it on the currently open text in
      >NoteTab and search the use of the currently
      >highlighted word.

      (BTW, cc'd to ntb-scripts since material herein is more so on topic at
      ntb-scripts@yahoogroups.com than it is here at ntb-clips@yahoogroups.com)

      a clip can_do/able to: 1. gettext the selected word into a clip variable. 2.
      launch and hand_off/pass the commandline to perl

      >Alternatuively, if the Perl script can be part of a
      >Clip, that'd be cool, too.

      In order to run a Perl script with such script's target is a Ntab doc then need
      to do like number 1 and 2 that I enclosed above.

      The version of script you shared has bits and pieces missing and many syntax
      errors. Part of a heredoc in it was missing. And,

      if ($i==$opt_m){goto L;}

      is in it (goto is frowned upon by those who are structured programming language
      programmers) -- Perl is a structured programming language.

      So you may need to upload it to the files area in hope of avoiding this the
      missing pieces etc.

      The script is not very well documented. I'm not argueing about whether the
      script works or not -- these are just firsthand observations on my part at this
      point, that's all. The script will not run here and it's too messed up, too much
      missing etc.

      die $usage unless scalar(@ARGV)>1;
      $SearchPattern = shift;
      CheckReMsg($SearchPattern);
      $filnm=shift;

      shift brings one item off. search word is first to come off, file name comes off
      2nd.

      (@ARGV)>1 means commandline *must* have more than 1 item such said items *must*
      be a space delimited list. (if U have Win filepaths with space in them, you are
      in for some fun) must either not do that or 1st pass program~files/file~path then
      first thing in Perl substitute each tilde (~) for a space (with space in, as
      another alternative, getshort in ntab might make it work). I just set mine up
      without space in any file path is how I did it. But I once had space and
      overcame it with tilde substitute to space as a workaround. then set all up
      without space character.

      current doc in ntab clip code is: ^**

      ^!RunPerl is reserved for to *operate* on and modify the current doc.

      Not operating and/or modifying current doc in this case. Just searching instead.

      Which is why I agree with Alec ie the ^!RunScript.

      So, item 1 of commandline is file_path_name_of_your_perl_script

      then come the two shift mentioned above. Which leave us with something in ntab
      clip like:

      ^!RunScript $getperlexe$ file_path/kwic search_word ^**

      And when ntab runs that it evaluates/equates to:

      Perl file_path/kwic search_word path_filename_of_current_doc

      each parameter separated by a space, that's four parameters

      those get passed from ntab to Perl (insert image of something working, beast of
      burden or tractor etc.) Perl *works* and then, where Perl's output goes in this
      case I do not know but it rather likely goes to STDOUT

      which leads to: I slightly goofed on the command above. To capture STDOUT with ntab:

      $GetDosOutput$

      Ya don't need ^!runscript. All U need is the *evaluated* command and to capture
      the output from that:

      ^!Set %curdoc%=^**
      ^!Toolbar "new document"
      ^!Insert $GetDosOutput($getperlexe$ file_path/kwic search_word ^%curdoc%)$

      ^^that^^ 3 lines ntab clip code brings evaluated command passed to Perl and
      captures Perl's output in ntab. And, note that the entire command is wrapped
      with the ntab function GetDosOutput. But if U want output to go to command
      console I leave as another exercise for another time.

      Alan.


      ---- Msg sent via CWNet - http://www.cwnet.com/
    Your message has been successfully submitted and would be delivered to recipients shortly.