News for hackers. Stuff that matters.
Re:We were wizards – a foreword to Learning Perl by fulafel on Sunday March 17, 2024 @06:02AM (#39733216)
About Python, are there practical situations outside IRC where you can't include a newline in there? This ..

  python -c '
  import re, sys
  for line in sys.stdin: print(line.lower().count("foo"))
  '
works in shell interactively (both bash and zsh support multiline history entries well), or in shell scripts, and also in slack/mattermost/matrix/email.
Re:We were wizards – a foreword to Learning Perl by teddyh on Sunday March 17, 2024 @06:11AM (#39733258)
You can do that as a one-liner (I have kept the unused “re” module import, to keep it as close to your code as possible):

  python -c 'import re, sys; print("\n".join(str(line.lower().count("foo")) for line in sys.stdin))'
or if you want to avoid building one large output string:

  python -c 'import re, sys; print(*(line.lower().count("foo") for line in sys.stdin), sep="\n")'
if memory consumption is still an issue:

  python -c 'import re, sys; set(print(line.lower().count("foo")) for line in sys.stdin)'
(This creates a useless Set object and throws it away as a side effect.)