Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I was trying to do the following:
$whatisit = system "whatis grep"; $whatisit =~ s/.*-//; print $whatisit;

Which didn't work, but if I test the regex with the actual output of whatis, then it does work:
$x = "grep (1) - print lines matching a pattern"; $x =~ s/.*-//; print $x;

This returns everything after the dash, which is what I want.

Replies are listed 'Best First'.
Re: How do I use a regex to parse $x = system
by turnstep (Parson) on Jan 27, 2001 at 15:35 UTC
    system returns a code indicated whether or not it succeeded. Since you want to capture the output, use backticks:
    my $whatisit = `whatis grep`;
Re: How do I use a regex to parse $x = system
by I0 (Priest) on Jan 28, 2001 at 22:11 UTC