Need to assign result of grep to var in PERL
I'm in PERL.
I've got a variable, say $x
I want to run a system call, say "grep -c mystring myfile", and assign the result of the grep back to $x.
When I say result of the grep, that would be what one would normally see in stdio... NOT the 0 (success) or errcode of the actual call to grep.
$x = system("grep -c mystring myfile");
but that just gives me 0 (indicating no error with the call to grep) rather than my expected count (which in my case is 14).
How do I get the $x to contain the value 14, or whatever the grep would spit out to stdio?