In some situations, the "slippery" way is to use the -n switch. It implicitly wraps your code with a while(<>) and flexibly controls the input signal.
In slickestWay.pl :
#! / usr / bin / perl -n
BEGIN: {
# do something once here
}
# implement logic for a single line of input
print $ result;
At the command line:
chmod +x slickestWay.pl
Now, depending on your input, do one of the following:
Wait for user input
./slickestWay.pl
Reading from files named in arguments (no redirection required)
./slickestWay.pl input.txt ./slickestWay.pl input.txt moreInput.txt
Use the handset
someOtherScript | ./slickestWay.pl
A BEGIN necessary if you need to initialize some kind of object-oriented interface, such as Text :: CSV or some that you can add to shebang with -M .
-l and -p are also your friends.
Neil Best Feb 10 '14 at 17:25 2014-02-10 17:25
source share