add piping as parameter to a simple perl script
I need median in one of my bash scripts.
A friend of mine is encouraging to leave bash alone and start with perl. On the inet I found this little perl implementation which I now want to use within my bash scripts. A little executable file in /usr/local/sbin/median Code:
#!/usr/bin/perl Code:
# echo '3 Code:
# median 3 1 3 4 5 2 If no command line is given it should take STDIN as the parameter. This could be a (very belated) start with perl for me... I would really appreciate any input |
Hi.
Code:
#!/usr/bin/perl Code:
$ echo 3 1 3 4 5 2 | tr ' ' '\n'| ./median.pl |
Thanks, but do you know how to elegantly support both ways and preferably without needing a "tr ' ' '\n'" ??
The command-line should take precedence |
Code:
#!/usr/bin/perl Code:
echo "1 5 9 82 15" | ./median.pl Code:
echo " Code:
echo "1 5 9 Code:
./median.pl 1 5 9 82 15 |
Thanks, thanks, thanks...
Hoping I don't overask, but how would it look if it needs to work like this... Code:
cat <file> median That's how other functions like sed and grep work: Code:
cat <file> median |
Hi.
Quote:
Code:
#!/usr/bin/perl |
All times are GMT -5. The time now is 11:17 AM. |