in reply to How do I read data passed to perl script
This will either take direct STDIN (run the program, it sits there, you enter lines of text until you hit ctrl-D), or take a list of filenames on the command line and process their contents as STDIN. Because this idiom doesn't use any textual identifier (like ARGV or STDIN), and because it's a difficult concept for a newbie to describe or search for (or even to conceive of), it's often something people don't pick up on early. I'm going to go on a limb and counsel a novitate to "just do it," and adapt your intentions to fit this idiom.while (<>) { # do stuff on $_ line by line }
It's not exactly what you described -- the others' @ARGV solutions are for that -- but if you can alter your requirement slightly, writing programs as filters has a lot of benefits. See The Art of Unix Programming for why.
|
|---|