[EMAIL PROTECTED] wrote: > Hi all, Hello,
> How do I parse or evaluate the output of UNIX commands? > > For example, in UNIX scripts, I can run filesystem=`df -k | awk -F"" ' { print > $6 }'` to check for the mount points. > > How do I achieve the same in Perl? That is, I tried: > > #!/usr/bin/perl > $x=system 'df -k'; > print "============================= \n"; > print $x . "\n"; The usual way to do it: #!/usr/bin/perl use warnings; use strict; open my $PIPE, 'df -k |' or die "Cannot open pipe from 'df' $!"; print '=' x 29, "\n"; while ( <$PIPE> ) { next if $. == 1; # skip first line -- header my $mount_point = ( split )[ 5 ]; print "$mount_point\n"; } close $PIPE or warn $! ? "Error closing 'df' pipe: $!" : "Exit status $? from 'df'"; John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>