in reply to How to write a program to read stdin or command line?

perl -nle"print $_ . 'world'" file

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: How to write a program to read stdin or command line?
by ikegami (Patriarch) on Oct 02, 2007 at 16:28 UTC
    if that's what the OP means by "stdin or command line", you could also use -p instead of -n:
    perl -ple"$_ .= 'world'" file
      if that's what the OP means by "stdin or command line",

      Seems it was.

      you could also use -p instead of -n:

      You could, but I wouldn't as it is less flexible than -n.

      If you want to omit some lines from the output, you can't do that if you are also using -l


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Assuming I was talking about the general case, how is -p less flexible? And how does -l matter?

        perl -nle "print bar($_) unless foo($_)"
        perl -ple "next if foo($_); $_=bar($_)"