PERL, How to pipe out put of a perl script for processing with linux command.
Hi
I have an array which stores some rules ID's which I extracted from a log file. What I would like to do is feed this array content to linux 'sort -nu' command and find out the unique rule IDs. But I don't want to redirect perl out to this command like perl id.pl | sort -nu Instead I would like to do this inside the perl script and get the uniqe IDs with 'perl id.pl'. Is it possible to do this. ie: Feed the data contained within an array of a perl script to a linux command for processing. I know it is very easy to catch the out put of a linux command in perl script like $x = `cat /etc/passwd`; Similrly, is the reverse thing possible?. Feed the conents of an array to a linux command for further processing. Code:
$x = `cat log.txt`; 380025 380025 380025 380025 380025 340155 340155 I would like to find the unique rules by feeding the ID's stored in @ar2 to 'sort -nu' command. It can be done like this Code:
# perl id.pl | sort -nu I am newbie in PERL programming. I am trying to learn how to mix perl and linux commands to obtain a desired result. |
Hi,
sort numerical with Perl Code:
sort {$a<=>$b} @ar ; Code:
my %uniq; |
After putting your sample data into 'LQSojiAntony.dat'...
Code:
perl -e '@array=<>; open(SORT,"| sort -nu"); print SORT @array; close SORT;' LQSojiAntony.dat Code:
340155 --- rod. |
Hi Thenbomr, Markush
Thank you so much for your kind responses. |
All times are GMT -5. The time now is 10:35 PM. |