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

I know this must be documented somewhere, but since I have an account here and have never posted a question, I figured I better say something soon!
perl -pi -e 's/mike/meathead/ig' */*
The above code does what I want, but let's say that I also want to do an inline-edit of all of the files in my current directory. What could I add to the above code to accomplish this, as well? I really would like to do this with wildcards. Thanks!

Replies are listed 'Best First'.
Re: simple command-line question
by gellyfish (Monsignor) on Mar 04, 2002 at 22:11 UTC

    You want to look at what the switches '-p' and '-i' do in the perlrun manpage - however you should bear in mind that the '*/*' part is a 'wildcard' that looks at the files in all of the subdirectores of the current directory - if you want to only operate on files in the current directory then you should have only '*'

    /J\

Re: simple command-line question
by I0 (Priest) on Mar 04, 2002 at 22:10 UTC
    perl -pi -e 's/mike/meathead/ig' */* *
Re: simple command-line question
by hsmyers (Canon) on Mar 05, 2002 at 13:52 UTC
    You might also look at 'perldoc -f glob' as well. For example:
    #!/usr/bin/perl use strict; use warnings; for (@ARGV) { for (glob) { print $_,"\n"; } }
    This is a quick and dirty basis for any filter...it could probably be 'mapped' into a one-line approach with the name of the 'filter' sub replacing 'print'.

    –hsm

    "Never try to teach a pig to sing…it wastes your time and it annoys the pig."
Re: simple command-line question
by rbc (Curate) on Mar 04, 2002 at 23:02 UTC
    for i in `find .`; do sed -e's/mike/meathead/ig' $i > ${i}_NEW ; done
        find . -type f -print0 | xargs -0 perl -i -pe 's/mike/meathead/ig'

        Might save you a few or several thousands of processes, depending on the number of files found -- and might be a good habit to make -- at least on systems where it works. (GNU find might be needed.)

        For anything more complex than one-liners, you might prefer to use File::Find;

        The Sidhekin
        print "Just another Perl ${\(trickster and hacker)},"