On Thu, Dec 15, 2011 at 07:36:37AM -0800, Melvin wrote:
> Hi,

Hello:

> I was trying to write a script to replace baby to bigboy in a file:-
> However the below script doesn't work Could someone help me???
> 
> #!/usr/bin/perl -w
> use strict;
> 
> open (FILE_IN , $ARGV[0]) || die ("ERROR: Gimme Input pleease");
> 
> my @array_of_lines = <FILE_IN>;
> 
> foreach my $line (@array_of_lines)
> 
> {
> $line =~ s/baby/bigboy/g;
> 
> }
> 
> close FILE_IN;

You are attempting to modify the file in place, but that isn't
how it works. :) You can apparently use the File::Slurp module to
do that though. IIRC from Uri's examples there's an edit_file
function. (*Checks documentation*) Oooh, neat:

#!/usr/bin/perl

use File::Slurp;

die 'invalid arguments' unless @ARGV;

edit_file { s/baby/bigboy/g } $ARGV[0];

__END__

Untested. >:)

Regards,


-- 
Brandon McCaig <bamcc...@gmail.com> <bamcc...@castopulence.org>
Castopulence Software <https://www.castopulence.org/>
Blog <http://www.bamccaig.com/>
perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.
q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.};
tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'

Attachment: signature.asc
Description: Digital signature

Reply via email to