Hacker News new | ask | show | jobs
by alaaalawi 1248 days ago
i like awk. but i hate Regexp (YMMV). but for different perspective check out SNOBOL or its speedier variant Spitbol. although not one liner, but i find patterns easier to compose like functions. $anchor = 0 digits = '0123456789' patt = "foo=" SPAN(digits) . num while line = INPUT if line ? patt OUTPUT = num endif end

end

NOTE1: reading variable INPUT. reads from input. assignment to OUTPUT writes to output. normally assigned to STDIN and SDTOUT, and can be configured.

NOTE2: there is no real while or if. flow is through labels and jumps (considered by some as power but i disagree). above example uses another script to transform while and if into labels and jumps. the point is that patterns composition and success match assignment.

1 comments

i. missed up the code

  digits = '0123456789'
  patt = "foo=" SPAN(digits) . num
  while line = INPUT
      if  line ? patt
          OUTPUT = num
      endif
   end