Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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
Replies are listed 'Best First'.
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 meditating upon the Monastery: (16)
As of 2015-07-31 15:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (279 votes), past polls