Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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.

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 chilling in the Monastery: (6)
As of 2016-09-24 23:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (462 votes). Check out past polls.