User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Perl section within the Software Development category of DaniWeb, a massive community of 429,841 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,840 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Perl advertiser: Programming Forums

perl code

Join Date: May 2008
Posts: 6
Reputation: prakasnisha is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
prakasnisha prakasnisha is offline Offline
Newbie Poster

Re: perl code

  #6  
May 15th, 2008
Originally Posted by katharnakh View Post
Hi,
Please go through this, before posting your code. Its not an assignment, just a prerequisite if you want to get really quick help.

Only with code it is hard to know what is working and what is not. Provide some input(example) details. Post your errors, if any OR if you are getting output, post it and explain, how you want it to be or how different it is from what you want.

katharnakh.



hello,
i have written the code, but the output is not coming properly.

i have to write a script which can automatically update the old file with new values. for example, i have a file which has few commands in it along with other data( like vdd_power; ac_current,etc). now i have to replace these values in that file with the new values(like vddPOWER;AC_current).and everytime i run the script on such file, it should automatically update the file.

when i run this code, i m getting the file with the replaced values but the file is now containing only the new values, all the old data has been overwritten with the new one.and also i have hard coded it.is there any other way to do it? plz help me .

thanks & ragards
Nisha


the code is:-
#!/grid/comon/bin/perl
$dir="../nishap";
$sub="nisha";
$path="$dir/$sub/$file";
#print "$path\n";
open(OLD_DATA1,"$path") or die("cant open the file $path");
#open(OLD_DATA,"../nishap/nisha/old_data.txt") || die "cant open the file $path";
while($line=<OLD_DATA1>)
{
chomp($line);
if($line =~/^abc_xyz_cwd$/)
#if($line =~/^(\w+(.*))$/)
{
# print "$line\n";
$data1=$line;
$data1=~s/abc_xyz_cwd/abc_xyzcwd/gi;
print "$data1\n";

}
if($line=~/^aa_aa$/)
# if($line =~/^(\w+(.*))$/) ----is this correct??
{
$data2=$line;
$data2=~s/aa_aa/aaaa/gi;
print"$data2\n";
}

if($line=~/^bb$/)
{
#print"$line";
$data3=$line;
$data3=~s/bb/b_b/gi;
print"$data3\n";
}

if($line=~/^c_c$/)
{
$data4=$line;
$data4=~s/c_c/cc/gi;
print"$data4\n";
}

if($line=~/^dd_ee$/)
{
$data5=$line;
$data5=~s/dd_ee/dde_e/gi;
print"$data5\n";
}
}

close(OLD_DATA1);

$new="old_data1.txt";
open(OLD_DATA1,">>../nishap/nisha/old_data1.txt") or die("cant open the file $new");
{
print OLD_DATA1 "
$data1
$data2
$data3
$data4
$data5
\n ";
}
close(OLD_DATA1);
Last edited by prakasnisha : May 15th, 2008 at 1:08 pm.
Reply With Quote  
All times are GMT -4. The time now is 6:27 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC