On Tue, 2004-07-20 at 15:42, Baskaran wrote: > Dear sir, > > > I have two array variables. I want to find $a[1] and replace $b[1] in a > file. > ($a[1],$b[1] are array variables) > How to find and replace the variable contents. > > for ($i=0;$i<$totalnum;$i++){ > s/$a[i]/$b[i]/g; > } >
You have almost got it #!/usr/bin/perl # These are your arrays my @a = ( .... ); my @b = ( .... ); my $filecontent; if(open(IN,"FILENAME")){ local($/)=undef; $filecontent = <IN>; close IN; } else { die "error opening file $!"; } # Now do the substitue for ($i=0;$i<@a;$i++){ $filecontent =~ s/$a[i]/$b[i]/g; } # Write back to file open(OUT,">FILENAME") || die "blah"; print OUT $filecontent; close OUT; #Bye ######################## HTH Ram -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>