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

a clip 4 perl includes a pl script; also, perl's shift function

Expand Messages
  • Alan C.
    Hi, (further below is faqgrep.pl, a faq keyword searcher perl-doc-searcher script) (yet further below, a short musing on Perl s shift function and NoteTab-perl
    Message 1 of 2 , Mar 1 12:38 AM
    • 0 Attachment
      Hi,

      (further below is faqgrep.pl, a faq keyword searcher perl-doc-searcher script)
      (yet further below, a short musing on Perl's shift function and NoteTab-perl interactivity)

      As the clip stands now, toggle either of its 1st 2 lines

      H="AC*runscript_pl_ntbscripts"
      ^!Goto gdosoutput
      ; ^!Goto run_cur_pl_doc

      ; didn't need. perltidy comes equipped with .bat file
      ^!Set %ntpscripshort%=^$GetShort("^$GetScriptPath$")$
      ; ^!Set %myfile%=^?{(T=O)What file spec?}
      ^!Set %myfile%=^**
      ^!Set %myfile%=^$GetShort("^%myfile%")$
      ^!RunScript "^$GetPerlExe$ ^1 ^%myfile%" "^%ntpscripshort%perltidy.pl"
      ^!Goto end

      ; from ntb scripts folder - use 2 run & capture
      :gdosoutput
      ^!Set %kywrd%=^?{faqgrep Enter search or keyword=sort}
      ^!ChDir ^$GetShort("^$GetScriptPath$")$
      ; ^!Append %cmnd%=^$GetPerlExe$ ^$GetShort("^$GetScriptPath$tag2para.pl")$
      ^!Append %cmnd%=^$GetPerlExe$ faqgrep.pl
      ^!Toolbar New Document
      ^!InsertText ^$GetDosOutput("^%cmnd% ^%kywrd%")$
      ^!ClearVariable %cmnd%
      ^!Goto end


      ; focused doc is a perl script - use 2 run & capture the output
      :run_cur_pl_doc
      ^!Set %myfile%=^**
      ^!Set %myfile%=^$GetShort("^%myfile%")$
      ^!Append %cmnd%=^$GetPerlExe$ ^%myfile%
      ; ^!ChDir ^%myfile%
      ^!Toolbar New Document
      ^!InsertText ^$GetDosOutput("^%cmnd%")$
      ^!ClearVariable %cmnd%
      ;---end of clip----

      right now, the clip (toggle) is set on gdosoutput which I use for the faqgrep.pl a script written by Andrew Johnson, author of the book "Elements of Programming With Perl"

      faqgrep.pl is next (you may need change the very top shebang line to path to your perl)

      #!/perl/bin/perl -w
      #line 154 "faqgrep.nw"
      use strict;
      #line 168 "faqgrep.nw"
      # set $faqdir to point to your installed pod files:
      # my $faqdir = '/usr/local/lib/perl5/5.00503/pod';
      my $faqdir = '/Perl/lib/pod';
      my($opt_f,$opt_or,$pattern);
      #line 177 "faqgrep.nw"
      while($ARGV[0]=~/^-/){
      $_=$ARGV[0];
      if (/^-or$/){$opt_or=1;shift @ARGV;next}
      if (/^-f$/){$opt_f=1;shift @ARGV;next}
      die<<HERE;
      illegal option: $_
      usage: faqgrep [-f] [-or] [keywords...]
      HERE
      }
      #line 197 "faqgrep.nw"
      die "no keywords specified\n" unless @ARGV;
      if($opt_or){
      $pattern = '.*(?:' . join('|',@ARGV) . ')';
      }else{
      $pattern=join('',map{"(?=.*$_)"}@ARGV);
      }
      #line 173 "faqgrep.nw"
      #line 209 "faqgrep.nw"
      opendir(FAQDIR,$faqdir)|| die "can't open $faqdir $!";
      my @faqs = grep /faq/,readdir FAQDIR;
      closedir FAQDIR;
      #line 220 "faqgrep.nw"
      foreach my $faq (@faqs) {
      open(FAQ,"$faqdir/$faq")||die "can't $!";
      while (<FAQ>) {
      if (s/^=head2($pattern)/$1/io) {
      print "$faq:$_" ;
      #line 234 "faqgrep.nw"
      if ($opt_f) {
      while(<FAQ>){
      last if m/^=head(?!$pattern)/io;
      print;
      }
      }
      #line 226 "faqgrep.nw"
      }
      }
      close FAQ;
      }
      #line 243 "faqgrep.nw"
      =head1 NAME

      faqgrep - perl script to search perlfaqs

      =head1 SYNOPSIS

      faqgrep [-f] [-or] [keywords...]
      faqgrep sort hash
      faqgrep -or sort hash
      faqgrep -f sort array

      =head1 DESCRIPTION

      This script takes keywords as arguments and searches through the
      perlfaqs printing on STDOUT the questions (and optionally the
      answers) which contain the keywords.


      =over 2

      =item -or

      By default, keywords are 'ANDed' together to find questions
      which contain ALL of the keywords. Using the B<-or> option
      'ORs' together the keywords to find questions which contain ANY
      of the keywords.

      =item -f

      By default only the matching questions are printed. Using this
      option causes the full entry (answer) of all matching questions
      to be printed. This can cause a lot of output unless the search
      was restricted. It is recommended that you first search
      for just one or two keywords and see the resulting matches and
      then repeat the search using B<-f> and additional keywords to
      restrict output to just those entries you wish to see.

      =back

      =head1 AUTHOR

      Andrew L. Johnson <andrew-johnson@...>

      =head1 COPYRIGHT

      Copyright 1997-1998 Andrew L Johnson.
      This is free software and you may redistribute it and/or
      modify it under the same terms as Perl itself.

      =cut
      #line 159 "faqgrep.nw"

      # faqgrep.pl ended on the previous (blank) line


      Alan C. wrote:

      perldoc -f shift
      (I noticed shift function is used in above perl script)

      shift function will (I think) be one of the keys to interfacing via command line with NoteTab to interface NoteTab with Perl.

      @ARGV is the (Perl) commandline (that I had passed to a Perl script using NoteTab to pass to Perl)

      so, for example:

      perl myplscript.pl myfile1 myfile2 myfile3

      Use NoteTab to send that as well as caputure getdosoutput of that command

      once the Perl script is running, perl's @ARGV contains the above command that was issued to perl by NoteTab (via the command line)

      the shift (not shown) in myplscript.pl is function that can make same script work on the specified file(s)

      (say, 4 finding things in files to return found results into NoteTab)

      BTW I got the Mastering Perl/Tk book, picked up on Ebay, the book not yet arrived.

      --
      Later. Alan.
    • Sheri
      ... I ve been reading it online on a 2 week trial subscription at O Reilly Network Book Safari. http://safari.oreilly.com/ Not much chance I would become a
      Message 2 of 2 , Mar 1 6:59 AM
      • 0 Attachment
        At 12:38 AM 3/1/03 -0800, Alan wrote:
        >BTW I got the Mastering Perl/Tk book, picked up on Ebay, the book not yet arrived.

        I've been reading it online on a 2 week trial subscription at O'Reilly Network Book Safari.

        http://safari.oreilly.com/

        Not much chance I would become a paying member, but I must admit this is a nice library. I have five or six more days. During the 2 week trial, you can access up to 10 books.

        They use XML in their process btw (not that I know anything about it).

        All I've accessed is MPTK. I don't know what I did, but somehow I managed to trigger an "unusual usage alert" and they sent me an email warning and threatened to lock me out :(

        "Please make sure that you are not running programs that 'speed-up' web browsing; or that spider, crawl, or capture web pages for offline viewing. These types of tools will trigger further alerts and violate the Safari Terms of Service."

        Keep the above in mind if you decide to try it yourself.

        Regards,
        Sheri
      Your message has been successfully submitted and would be delivered to recipients shortly.