Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

find and replace in perl

by torres09 (Acolyte)
on Jun 24, 2013 at 05:40 UTC ( #1040360=perlquestion: print w/replies, xml ) Need Help??
torres09 has asked for the wisdom of the Perl Monks concerning the following question:


I am working with text file and it looks like "5300;; val ;; ;;6;; 1;; 1;; -50;; 50;; ;; ;; ;; ;; ;; ;;"

and I just want to replace ;; with comma , how can i do it

Replies are listed 'Best First'.
Re: find and replace in perl
by prashantktyagi (Scribe) on Jun 24, 2013 at 05:46 UTC
    $string =~ s/$pattern/$replace/g

      can't we do the find and replace operation via perl on the entire text file , without taking it into an array

      like say find and replace on a file handler . sorry I am new to perl , so I don't have a lot of command on it

        perl -pi.bak -e 's/pattern/replace/g' filename.txt


        sorry I am new to perl

        :) I read perlintro every day, and I'm very old to perl :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1040360]
Approved by Happy-the-monk
[Discipulus]: good morning monks and nuns!
[Corion]: A good morning Discipulus! ;)
[Discipulus]: ah! all was well Corion?

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2018-02-22 08:06 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (288 votes). Check out past polls.