2
With grep
I get a failure return code/exit status if no result is found.
How can I do the same thing with perl?
Basically, I would like to change the following so that it exits with status 1 if no match is found.
echo foo | perl -nle'print if m{bar}'
1That prints "1", but doesn't exit with status 1/failure. – hpique – 2014-12-04T04:57:58.577
1
you can replace print 1 with
– Frank Thomas – 2014-12-04T05:59:15.440die 1
(for failure; should abort script) orexit 1
(return status of 1, but don't throw error) if you want. http://perldoc.perl.org/functions/exit.htmlHi. Like Frank said, die or exit will return 1 or failure. – Eamonn Travers – 2014-12-04T08:22:20.927