Beefy Boxes and Bandwidth Generously Provided by pair Networks BBQ
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

s// All Files In Directory

by perl.j (Pilgrim)
on Apr 02, 2012 at 19:26 UTC ( #963094=perlquestion: print w/ replies, xml ) Need Help??
perl.j has asked for the wisdom of the Perl Monks concerning the following question:

Hello!

So here is my problem: I want to go through all of the file in a directory, and s/5/6/.

How can I open all of the file in the directory, and substitute all of the 5s for 6s?

--perl.j

Comment on s// All Files In Directory
Download Code
Re: s// All Files In Directory
by Anonymous Monk on Apr 02, 2012 at 19:34 UTC
Re: s// All Files In Directory
by Happy-the-monk (Monsignor) on Apr 02, 2012 at 19:37 UTC

    How can I open all of the file in the directory, and substitute all of the 5s for 6s?

    perldoc perlrun yields the answer to your question. Have a look for -pi.

    Cheers, Sören

      I'm not too good with the command line (I'm a Windows guy :-). So in what syntax would I use -pi?
      --perl.j

        Learn to be good with the command line. Being saddled with Windows is no excuse; if you can't stand the Windows command line (I can't), install Cygwin.

        -p process line-by-line and print the results -i operate on files in place -e execute the following code Hence: perl -p -i -e 's/foo/bar/g' *

        Aaron B.
        My Woefully Neglected Blog, where I occasionally mention Perl.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://963094]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2014-04-21 13:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (495 votes), past polls