On 07/28/2010 05:53 PM, Stuart Cooper wrote:
> Hi Damian,
> 
>> my $first_line = `grep -v '#' $filename|head -n 1`; # to get the first
>> non-comment line
> 
--extra code deleted--

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

Could you elaborate on why?  I tried it and it worked for me.

> 
> 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.

In fact, I tried your code snippets as well as the OP's, and the only
error I saw, with a misspelled command name, was:

  sh: ehead: command not found

I tried this without changing any signal and with "$SIG{'PIPE'} =
'IGNORE'", no difference.

In other words, the shell, when setting up the command, verifies it can
find all commands in the pipe sequence before it tries anything else.

Now, when I gave 'head' an invalid option, so it was found and ran, but
exited *without* reading the input, then I got the broken pipe error.
But I also got an error from 'head' about invalid options.

Bottom line is I can't figure out what it is that is 'not valid' in the
original?

-- 
Bob McGowan

Reply via email to