CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
writing Files

 



stavros
New User

Jun 23, 2011, 10:30 AM

Post #1 of 3 (466 views)
writing Files Can't Post

Hello,

i need your help in a small programme that i want to create.
i have a file which contain the following

name1 1481.100 1436.550 1460.410 1444.460 1049.120 1076.890 1085.500 1053.100
name2 1978.700 1949.910 1734.030 1694.530 1930.000 2005.530 1696.960 1844.810
name3 ...

and i want to write it as it is in a new file by only replacing the values with log(value)

so i use this programme

my $Name = "";
my $Value1 = 0;
my @files = glob ('*.txt');

sub log10 {
my $n = shift;
return log($n)/log(10);
}


open (MYFILE, '>data.txt');



foreach my $file (@files)
{
#print "$file\n";
$test = "$file";
open (TEST,"$test") || die "couldn't open the file YEASTFASTA:$!";
while (<TEST>)
{
my $line = $_;

if ($_=~/^\d+[_]\w+\s+(\S+)\s+(\S+)\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+.*/)
{
#$Name = $1;
$Value1 = $2;
$LogValue = log10($Value1);
print MYFILE "$LogValue";
#print "d $LogValue \n";
}

print MYFILE "$_";
}
close TEST || die "can't close:$!";
close (MYFILE);

}

and the output i take is

1.37852508154491 name1 23.907 15.022 25.234 22.573 21.541 13.972 25.076 17.099 YLR331C
3.17058438193919 name2 1481.100 1436.550 1460.410 1444.460 1049.120 1076.890 1085.500 1053.100

so my point is how can i place the value 1.3785250815449 (which is the log(23.907)) not in the begging of the line but instead of the value 23.907, that means that i want this output
name1 1.3785250815449 ...(log of all the values).

Thanks in advance for your time.
Biomedical Engineer


miller
User

Jun 23, 2011, 12:01 PM

Post #2 of 3 (462 views)
Re: [stavros] writing Files [In reply to] Can't Post

Check cross-posting at perlmonks:

http://www.perlmonks.com/?node_id=911121

- Miller


stavros
New User

Jun 28, 2011, 11:01 AM

Post #3 of 3 (430 views)
Re: [miller] writing Files [In reply to] Can't Post

thank you very much for your help.Wink
Biomedical Engineer

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives