如何使用Perl替换grep来保留文件名

Geo*_*pty 2 perl command-line grep

使用grep考虑以下命令行输出:

[gjempty@gjempty]$ find . -name "*.php" | xargs grep __construct | tail
./ilserverd/src/php/ImageLoopIntegrationService.php:  public function __construct($input, $output=null) {
./ilserverd/src/php/ImageLoopIntegrationService.php:  public function __construct($vals=null) {
./ilserverd/src/php/ImageLoopIntegrationService.php:  public function __construct($vals=null) {
./ilserverd/src/php/ImageLoopIntegrationService.php:  public function __construct($vals=null) {
./ilserverd/src/php/ImageLoopIntegrationService.php:  public function __construct($vals=null) {
./ilserverd/src/php/ImageLoopIntegrationService.php:  public function __construct($handler) {
./ilserverd/src/php/il_server_types.php:  public function __construct($vals=null) {
./ilserverd/src/php/il_server_types.php:  public function __construct($vals=null) {
./utilities/studio/legacy/full_bleed_update_photobook_themes.php:    public function __construct() {
./utilities/studio/legacy/full_bleed_update_photobook_themes.php:        parent::__construct();
Run Code Online (Sandbox Code Playgroud)

这是我尝试提取构造函数参数的第一步,因为它需要许多步骤,我试图使用Perl作为对grep的改进.但首先,我想保留文件名,以便我可以参考最终"报告"输出中的文件名.

但是当我切换到下面的Perl单线程时,文件名不再是输出的一部分.我如何保留它们仍然使用Perl作为grep的命令行替换?

[gjempty@gjempty]$ find . -name "*.php" | xargs perl -wnl -e '/__construct/ and print' | tail
  public function __construct($input, $output=null) {
  public function __construct($vals=null) {
  public function __construct($vals=null) {
  public function __construct($vals=null) {
  public function __construct($vals=null) {
  public function __construct($handler) {
  public function __construct($vals=null) {
  public function __construct($vals=null) {
    public function __construct() {
        parent::__construct();
Run Code Online (Sandbox Code Playgroud)

cod*_*ict 5

您可以尝试使用$ARGV:

perl -wnl -e '/__construct/ and print "$ARGV: $_"'
Run Code Online (Sandbox Code Playgroud)