Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replacing a particular value in a file 1

Status
Not open for further replies.

ktsrikanth

Programmer
Feb 6, 2001
22
0
0
US
Hi all,
I have a file as

ssss:2345
safsaf:242
fsfs:2214

I need to change the value in the second column based on the value of the first column.

Please do send me a code for this. I am hung up. I am in need of this code immediatly. Please help me





 
That doesn't sound like a big problem, but we need a little more info. How are the two columns related? How does the value of the first column affect the value of the second column? Etc.?
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Hi tsDragon,
Thank you for the mail.
There is no relation between the first andd the second columns. They are like the key value pairs.

That is all

Please do help me

Thank you

 
You could use an eval on the right side of a replacement and do what ever you like in the eval'd sub.

maybe this will do what you want....???

$str =~ s/(.*?):(.*)/&convert($1,$2)/ei;

sub convert
{
my $col_1 = shift;
my $col_2 = shift;
# do something to $col_2 based on the value of $col_1 and return
# content you want back to the right side of the replace.
my $tmp = "$col_1$new_col_2;
return ($tmp);
}




keep the rudder amid ship and beware the odd typo
 
how about this?

s/:242$/:444/o if /^safsaf:/;
Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top