Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: string value assignment

by ciderpunx (Vicar)
on May 14, 2011 at 11:14 UTC ( #904812=note: print w/ replies, xml ) Need Help??


in reply to string value assignment

Its normally helpful if you post your code and describe what you are having difficulty with. But I'm at a loose end so try:

#!/usr/bin/perl use warnings; use strict; open (IN, 'first.txt') or die ("crap! $!"); my @first = <IN>; close IN; open (IN, 'second.txt') or die ("crap! $!"); my @second = <IN>; close IN; my %h; my $i=0; for (@second) { ($h{'A'},$h{'B'},$h{'C'}) = split / /,$_; my @keys = split //,$first[$i]; my $total = 0; for(@keys) { $total+= int($h{$_}) unless /\n/; } $total/=scalar(@keys) if($total); print "$i: $total \n"; $i++; }



Comment on Re: string value assignment
Download Code
Re^2: string value assignment
by abidq (Initiate) on May 14, 2011 at 11:33 UTC
    dear charlie (cider...)

    i want the two calculated values (at 1pm and 2pm) for each string separately that is out put file should be like this for two different strings:

    1pm:2, 2pm:22 #string1

    1pm:1.4, 2pm:9 #string2

      Post your code and tell us where you are stuck then.

        #!/usr/bin/perl $line=$ARGV[0]; $name=$ARGV[1]; chomp($line); chomp($name); $amino="ABC"; @cc=split(//,$amino); $line=~ s/[\s]//g; @prot=split(//,$line); $len=@prot; open(NAS,">>$name"); print NAS"0"; close NAS; open(MAJ,"valfile"); while($li=<MAJ>){ chomp($li); $val=""; @value=split(/ +/,$li); for($p=0;$p<@prot;$p++){ for($a=0;$a<@cc;$a++){ if($prot[$p] eq "$cc[$a]"){ $val +=$value[$a]; } } $val1=$val/$len; $val1=sprintf "%5.3f",$val1; } $number++; open(MAL,">>$name"); print MAL" $number:$val1"; close MAL; } close MAJ; open(MAL1,">>$name"); print MAL1"\n"; close MAL1;

        THE PROBLEM WITH ABOVE CODE IS THAT IT TAKES ONLY ONE STRING AT A TIME (i.e. ONLY FIRST LINE) WHILE I WANT TO INPUT MANY STRINGS AT A TIME (IN DIFFEREENT LINES) FOR CALCULATION

        we cant solve it
        sorry i got asleep while solving now listen:

        #!/usr/bin/perl $line=$ARGV[0]; #input file1 containing string list $name=$ARGV[1]; #output file, given at linux command chomp($line); chomp($name); $amino="ABC"; @cc=split(//,$amino); $line=~ s/[\s]//g; @prot=split(//,$line); $len=@prot; open(NAS,">>$name"); print NAS"0"; close NAS; open(MAJ,"valfile"); #input file 2 containing values while($li=<MAJ>){ chomp($li); $val=""; @value=split(/ +/,$li); for($p=0;$p<@prot;$p++){ for($a=0;$a<@cc;$a++){ if($prot[$p] eq "$cc[$a]"){ $val +=$value[$a]; } } $val1=$val/$len; $val1=sprintf "%5.3f",$val1; } $number++; open(MAL,">>$name"); print MAL" $number:$val1"; close MAL; } close MAJ; open(MAL1,">>$name"); print MAL1"\n"; close MAL1;

        this code finely processes the string but only line 1 ;your job is to make it take all lines of string LIKE THE WAY IT TAKES ALL LINES FROM VALUES (input file 2 ) FILE. also go through my original question where instructions/pseudo code is given

        i am ashamed of my behaviour

        i ask for your forgiveness

        sorry for writing capitals

        and being informal in spelling

        i hope inspite of my fallacies you would try to help me out

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://904812]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (11)
As of 2014-07-22 09:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (109 votes), past polls