Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: How to write a program to read stdin or command line?

by BrowserUk (Pope)
on Oct 02, 2007 at 16:10 UTC ( #642153=note: print w/ replies, xml ) Need Help??


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.


Comment on Re: How to write a program to read stdin or command line?
Download Code
Re^2: How to write a program to read stdin or command line?
by ikegami (Pope) 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($_)"

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://642153]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2014-10-25 07:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (142 votes), past polls