Re: Rookie Perl Question



swangdb wrote:

I want to run some unix commands from a perl script.

This works, it prints out all lines that don't begin with a # in the
file $ALIASES:

***
$temp = "egrep -v \^# $ALIASES";
system($temp);
***

This doesn't work, it tries to take the egrep output and cut out part
of it:

***
$temp = "egrep -v \^# $ALIASES | cut -d: -f1";
system($temp);
***

I get the following output:

Usage: egrep [OPTION]... PATTERN [FILE]...
Try `egrep --help' for more information.

How can I make this work?

Thanks!

$aliases = 'some/file/name';

open( FH, $aliases ) || die "opening aliases: $!\n";

while ( <FH> )
{
print if ( ! m/^[#]/ );

} ## end while

close( FH );

## FYI: Buy Perl programming book "Learning Perl" ISBN: 1-56592-284-0.

## The system() call doesn't return output to you.
## Another means is open( FH, "egrep -v ... |" ) which opens a piped FH.

.