Re: Find and Replace in Textfile

2011-08-22 Thread John W. Krahn
C.DeRykus wrote: If you're permitted a one-liner: perl -pi.bak -e '$c=s/Dood\/Dude/ if !$c++' file $ perl -c -pi.bak -e '$c=s/Dood\/Dude/ if !$c++' Substitution replacement not terminated at -e line 1. John -- Any intelligent fool can make things bigger and more complex... It takes a t

Re: Find and Replace in Textfile

2011-08-22 Thread C.DeRykus
On Aug 21, 4:33 am, xecro...@yahoo.com (Ron Weidner) wrote: > Recently, I was asked to find the first occurrence of a word in a text file > and replace it with an alternate word.  This was my solution.  As a new Perl > programmer, I feel like this solution was too C like and not enough Perl > li

Re: Find and Replace in Textfile

2011-08-22 Thread Randal L. Schwartz
> "John" == "John W Krahn" writes: John> ?Dood? && s/Dood/Dude/; Deprecated in 5.14. Replace with m?Dood? and you're good though. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technica

Re: Find and Replace in Textfile

2011-08-21 Thread Uri Guttman
> "JWK" == John W Krahn writes: JWK> There are a few ways to do what you require: and you missed the simplest one so far (i did mention edit_file): JWK> #!/usr/bin/perl JWK> use strict; JWK> use warnings; use File::Slurp qw( edit_file ) ; my $file = 'data.txt' ;

Re: Find and Replace in Textfile

2011-08-21 Thread Uri Guttman
> "JWK" == John W Krahn writes: JWK> There are a few ways to do what you require: and you missed the simplest one so far (i did mention edit_file): JWK> #!/usr/bin/perl JWK> use strict; JWK> use warnings; use File::Slurp qw( edit_file ) ; edit_file { s/Dood/Dude/g } $file

Re: Find and Replace in Textfile

2011-08-21 Thread John W. Krahn
Ron Weidner wrote: Recently, I was asked to find the first occurrence of a word in a text file and replace it with an alternate word. This was my solution. As a new Perl programmer, I feel like this solution was too C like and not enough Perl like. So, my question is what would have been the P

Re: Find and Replace in Textfile

2011-08-21 Thread Uri Guttman
> "SHC" == Shawn H Corey writes: SHC> On 11-08-21 07:33 AM, Ron Weidner wrote: >> Recently, I was asked to find the first occurrence of a word in a text file and replace it with an alternate word. This was my solution. As a new Perl programmer, I feel like this solution was too C like

Re: Find and Replace in Textfile

2011-08-21 Thread Rob Dixon
On 21/08/2011 13:21, Rob Dixon wrote: Hey Ronald Here is a program like yours, that reads the entire file into memory and then outputs the altered version. #!/usr/bin/perl use strict; use warnings; #program finds the first occurrence of the word Dood and #replaces it with the word Dude in the

Re: Find and Replace in Textfile

2011-08-21 Thread Rob Dixon
On 21/08/2011 12:33, Ron Weidner wrote: > > Recently, I was asked to find the first occurrence of a word in a > text file and replace it with an alternate word. This was my > solution. As a new Perl programmer, I feel like this solution was too > C like and not enough Perl like. So, my question is

Re: Find and Replace in Textfile

2011-08-21 Thread Shawn H Corey
On 11-08-21 07:33 AM, Ron Weidner wrote: Recently, I was asked to find the first occurrence of a word in a text file and replace it with an alternate word. This was my solution. As a new Perl programmer, I feel like this solution was too C like and not enough Perl like. So, my question is w