Hi,
For replacing the contents of an array :
This code snippet replaces the string "MODIFIED" by "MOD"
foreach(@arr) {
s/MODIFIED/MOD/g;
}
foreach(@arr) {
 print "$_\n";
}

This is a round about way of assigning values of one array to another.
#!/usr/bin/perl -w
@arr1 = ("This","is","something","cool");
@arr2 = ("That","was","nothing","cool");

for($i=0;$i<scalar($#arr1);$i++) {
$arr1[$i]=~s/$arr1[$i]/$arr2[$i]/g;
}
foreach(@arr1) {
 print "$_\n";
}
Is this what you are looking at?
Am I missing something here?
--Prasanna

Moon, John 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;
}

Is it possible to do search and replace or kindly suggest me an idea


Thanking you

Regards
Baskaran NK



Please give us a little more information...

Is the record "fixed length", "packed", "delimited", or "other"?

What is the size of the file?

Is the occurrence of the value $a[i] only once per record?

Maybe a few lines of the file would help us...

jwm





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to