Dirk80 has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I want to tag all my emacs files. Here is my first version.

#!/usr/bin/perl use strict; use warnings; use File::Find; # tag "~/.emacs" system("etags \"C:/Documents and Settings/dirk/Application Data/.emacs +\""); # tag all .el files of "C:\Program Files\Emacs" find(\&tagEmacsFiles, "C:/Program Files/Emacs"); sub tagEmacsFiles() { if( -f $_ ) { if( $_ =~ m/\.[eE][lL]$/ ) { # option -a means append to TAGS file system("etags -a \"$File::Find::name\""); } } }

The tagging within the find function is not working. Why???

Here is the second version. This one is working.

#!/usr/bin/perl use strict; use warnings; use File::Find; my @file_list; # tag "~/.emacs" system("etags \"C:/Documents and Settings/dirk/Application Data/.emacs +\""); # tag all .el files of "C:\Program Files\Emacs" find(\&addEmacsFilesToList, "C:/Program Files/Emacs"); for my $file (@file_list) { system("etags -a $file"); } sub addEmacsFilesToList() { if( -f $_ ) { if( $_ =~ m/\.[eE][lL]$/ ) { push(@file_list, "\"$File::Find::name\""); } } }

Would be really interesting for my me why the first version is not working.

Thank you.

Greetings,

Dirk

Replies are listed 'Best First'.
Re: etags not working within function called by find
by ikegami (Patriarch) on Apr 30, 2010 at 16:15 UTC
    The only difference between the two is the current work directory at the time you call system. Does it work if you use no_chdir?
    find({ wanted => \&tagEmacsFiles, no_chdir => 1, }, "C:/Program Files/Emacs"); sub tagEmacsFiles { system("etags -a \"$File::Find::name\"") if /\.el$/i && -f $File::Find::name; }

      Thank you. With the option no_chdir it is working.

Re: etags not working within function called by find
by jethro (Monsignor) on Apr 30, 2010 at 15:54 UTC
    I tried your first script with 'echo' and 'cat' instead of 'etags' on linux and it worked. I wonder why you didn't simply use $_ instead of $File::Find::name?

    I would suggest to try with echo and cat (or whatever works on windows) too to check if the script has the correct filenames and can access them