Hi Damian,

> my $first_line = `grep -v '#' $filename|head -n 1`; # to get the first
> non-comment line

> the shell which is invoked inherits the SIGPIPE = 'IGNORE' state. This
> causes a
> grep: writing output: Broken pipe
> error as the grep tries to write to the head process which has exited.

head won't exit like this, regardless of the disposition of SIGPIPE.
The right hand side of your pipe isn't working. You may need to specify
| /usr/bin/head -n 1, in case your `` shell is being spawned with a
very restrictive
$ENV{PATH}.

It's a broken pipe because the right side of it is not valid.

Try playing around with this 10-liner:

#!/usr/bin/perl
use strict;
use warnings;

$SIG{'PIPE'} = 'IGNORE';
# $SIG{'PIPE'} = 'DEFAULT';

my $filename = '/etc/apache2/apache2.conf';
my $first_line;

# $first_line = `grep -nv '#' $filename| misspelledhead -n 1`; # to
get the first non-comment line
$first_line = `grep -nv '#' $filename| head -n 1`; # to get the first
non-comment line

print "first non comment line is $first_line";

Good luck,
Stuart.

Reply via email to