How do I get the same results in Perl as in csh

In csh I can do this

echo `ps -ef | grep root | awk '{print $2}'`

how would I get the same results using perl.

Thanks

ps -ef | perl -e 'while ( <> ) { @tmp=split; print "$tmp[1]\n" if /.*root.*/;} '

Thanks John,

But I didn't clarify that I want this in a perl script not command line.
This would include the ps -ef in the perl script.

Brad

This sounds like homework... that is not allowed on the forums

#!/usr/bin/perl
      @tmp=`ps -ef`; 
      foreach $val ( @tmp ){ 
      	 $_ = $val;
      	 if (/.*root.*/)
      	 {@ps=split; 
      	  print "$ps[1]\n"; 
      	 } 
      }

It should not matter where "ps -ef" comes from.

It's not homework Jim.
It's just me trying to understand Perl.

Thanks for your help.

Brad

To me it seems Perl is alot more convoluted than it is help
if your script is heavily entrenched with unix commands.

Whats the advantage of all the extra code when you can do the samething
with one line of code?
Is the perl code really that great of an advantage in
this case?

Thanks

Perl is a programming language. If you do heavy programming, Perl is more suited than shell scripting. But if all you want to do is parse and/or filter system command output, I will likely do shell scripting alone. For other cases, I will use Perl.

Perl is not convoluted. It is just your exact case that looks convoluted. There are many Perl one-liners floating all around on the Web to tell you it is not necessarily convoluted.

A one-liner that gives the same result as your shell command:

print map { [split(/\s+/, $_)]->[1] . "\n" } grep { /root/ } split(/\n/, `ps -ef`);

Is it convoluted? I don't think so. Think about doing that in C or Java.