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

^!RunPerl question

Expand Messages
  • Alan C.
    Hello, H= pl_tesstre ^!RunPerl pl_testre H= _pl_testre #!/perl/bin/perl -w while ($line = ) { for ($line =~ s/^ s+//) { print $line; } } # end ... Jun 19
    Message 1 of 3 , Nov 23, 2002
    • 0 Attachment
      Hello,

      H="pl_tesstre"
      ^!RunPerl pl_testre

      H="_pl_testre"
      #!/perl/bin/perl -w
      while ($line = <>) {
      for ($line =~ s/^\s+//) {
      print $line;
      }
      }
      # end

      -----begin sample---
      Jun 19 04:17:37 gateway
      Jun 19 04:17:37 gateway
      Jun 19 04:17:37 gateway

      Jun 19 04:18:01 gateway
      Jun 19 04:18:01 gateway
      Jun 19 04:18:01 gateway
      Jun 19 04:18:01 gateway
      -----end sample----

      (each and every line, including the blank line, in sample has 3 spaces at the beginning of each line)

      The above parent/called clip when run on the sample will eliminate/remove the blank line from the sample.

      But if I change the regex to

      $line =~ s/^\s\s\s//

      Then it leaves, does not remove the blank line.

      Can \s in Perl regex include/get the linebreak? Or is this something that NoteTab is doing?

      Thanks. Alan.
    • Alan C.
      Hello - I had queried, ... It s a Perl thing. One of my books told me. s means whitespace whether the whitespace be a space, a tab, a form feed, or a
      Message 2 of 3 , Nov 24, 2002
      • 0 Attachment
        Hello - I had queried,

        >Can \s in Perl regex include/get the linebreak? Or is this something that NoteTab is doing?

        It's a Perl thing. One of my books told me. \s means whitespace whether the whitespace be a space, a tab, a form feed, or a newline. So,

        $line =~ s/^ +//

        is what I needed so as to trim any and all leading spaces from lines and to do so without eliminating any blank lines.

        I select some text to work with. Then, 1st Perl script appears it works per each line or line by line until all selected lines been processed. The 2nd Perl script slurps the entire selection into the $text variable. (very cool there NoteTab/Perl--the selected text STAYS selected even when two Perl scripts are run back to back)

        Since it work on either a selection or if nothing selected then it works on the entire doc, the sample in a doc with only just the two ^!RunPerl lines and the two Perl called clips will do it if you want to play with it (Perl required on your Sys, of course)

        http://www.wrh.noaa.gov/cgi-bin/Sacramento/afd?SFOZFPSTO

        H="wthr_pl_ntb"
        ;some code snipped for brevity
        ^!Set %bgnsel%=^$GetRow$:1
        ^!Find "=" S
        ^!Jump -1
        ^!Jump LINE_END
        ^!Set %endsel%=^$GetRow$:^$GetCol$
        ^!SetCursor ^%bgnsel%
        ^!SelectTo ^%endsel%
        ^!RunPerl pl_trmleadspace
        ^!RunPerl pl_linclip

        H="_pl_trmleadspace"
        #!/perl/bin/perl -w
        while ($line = <>) {
        for ($line =~ s/^ +//) {
        print $line;
        }
        }


        H="_pl_linclip"
        #!/perl/bin/perl -w
        undef $/; # Enter "file slurp" mode.
        $text = <>; # This file/selection slurped into the scalar
        for ($text =~ s/\n\.< />=>.</) {
        print $text;
        }
        # end

        ---begin sample (ea line has 4 spaces at LH)---
        CAZ017-241130-
        SOUTHERN SACRAMENTO VALLEY-
        INCLUDING SACRAMENTO
        330 PM PST SAT NOV 23 2002

        .TONIGHT...MOSTLY CLEAR. AREAS OF FOG...LOCALLY DENSE. LOWS 43
        TO 48. LIGHT WINDS.
        .SUNDAY...AREAS OF MORNING FOG...LOCALLY DENSE. INCREASING
        CLOUDINESS. A SLIGHT CHANCE OF SHOWERS IN THE AFTERNOON. HIGHS 60 TO
        65. SOUTHWEST WINDS 10 TO 20 MPH.

        .< TEMPERATURE / PRECIPITATION
        SACRAMENTO 46 64 46 62 / 0 10 20 0
        SAC EXEC AIRPORT 45 62 45 61 / 0 10 20 0
        ----end sample-----

        --
        Thanks. Alan.
      • Alan C.
        Hello, Just to share a NTB/Perl (mostly perl) tidbit that I discoverd ... I discovered a shorter/less perl code that still accomplishes the exact same task.
        Message 3 of 3 , Dec 2, 2002
        • 0 Attachment
          Hello,

          Just to share a NTB/Perl (mostly perl) tidbit that I discoverd

          >H="_pl_trmleadspace"
          >#!/perl/bin/perl -w
          >while ($line = <>) {
          > for ($line =~ s/^ +//) {
          > print $line;
          > }
          >}

          I discovered a shorter/less perl code that still accomplishes the exact same task. The below clip is a replacement for the above clip. It's more/closer like the perl script in samplecode library--it uses perl's default variable: $_

          H="_pl_trmleadspace"
          #!/perl/bin/perl -w
          while (<>) {
          s/^ +//;
          print "$_";
          }
          # end

          --
          Alan.
        Your message has been successfully submitted and would be delivered to recipients shortly.