Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: string value assignment

by abidq (Initiate)
on May 14, 2011 at 11:33 UTC ( #904817=note: print w/replies, xml ) Need Help??


in reply to Re: string value assignment
in thread string value assignment

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

Replies are listed 'Best First'.
Re^3: string value assignment
by ciderpunx (Vicar) on May 14, 2011 at 11:48 UTC
    Post your code and tell us where you are stuck then.

      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

        There is nothing to be ashamed of.

        Writing in all caps is a common issue.

        Spelling is not an issue; we have many cultures and many native languages amongst the esteemed peers in our profession. English is not always the first language, and even when it is, not everyone has that particular skill. As you may note, I never once mentioned spelling in my advice.

        There is nothing to forgive. I was not offended. I was merely trying to help. Part of helping in this case was giving you an opportunity to see how you might be perceived differently than you'd intended. If it helps you, I am glad to have helped. If it does not help you, maybe someone else will be.

        As regards the technical challenge you face -- I am trying to help you. But we are having some communication problems. I hope to be able to help you further, as we clear those out.

        I will write no more of the social aspect of this; either I have helped you or I have not, and Time alone will tell this tale. I will, however, respond to the technical issues in that part of the thread.

        Relax, friend. We're all Perl people here. :-)

      #!/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

        In order to help you proceed, it would be very kind of you to provide the following:

        1) What is that first command line parameter supposed to be? You can simply give me a string to use, or better, if you have time, also explain what it is supposed to be in a more conceptual manner.

        2) Where in your script were you expecting to read in the lines from your two files and process them?

        We can solve this problem, but to do so we must BOTH understand what is going on. YOU possess the knowledge of what is to be done. WE possess the knowledge of how you can get it done in Perl. But we haven't connected these two bits of knowledge yet, and we must do that in order to make useful progress.

        OBSERVATIONS:

        1. In your opening note, you mention two input files. I don't see you opening any two files for input in the Perl script. If you want to read multiple lines from a file, you generally have to open it and read the lines in a loop. Sort of like this:
          #!/usr/bin/perl -w use strict; if (open INPFIL, "<file1.dat") { # File opened. Proceed. while (my $inpbuf = <INPFIL>) { # Next line from input file chomp $inpbuf; &processInputLine($inpbuf); } # Cleanup close INFPIL; } exit;
        2. In your script, you blindly absorb two parameters from the command line without explanation or recourse. I get it; you wrote the code, you know what needs to go on the command line. But you didn't pass that information along with the code, so I don't know what to put in there. I can see the second parameter needs to be a filename, and further deduce we will be writing something to that file. But there's no clue at all for an outsider to understand what is to be supplied with the first parameter. I like to give the user options:
          #!/usr/bin/perl -w use strict; # Grab command line parameters my ($seqcod, $outfnm) = @ARGV; # Avoid Perl warnings about undefined values if (!defined $seqcod) { $seqcod = ''; } if (!defined $outfnm) { $outfnm = ''; } # Ask user to supply missing parameters. Exit if user just presses En +ter. if ($seqcod =~ /^\s*$/) { print " Sequence Code: "; $seqcod = <STDIN>; } if ($seqcod =~ /^\s*$/) { exit; } if ($outfnm =~ /^\s*$/) { print "Output Filename: "; $outfnm = <STDIN>; } if ($outfnm =~ /^\s*$/) { exit; } # All parameters verified. Proceed. &doTheRealWork($seqcod, $outfnm); exit;

        I await your reply that we may proceed.

        edit: The script does open one file for read, but it does not open two.

      we cant solve it

        Ah, the wisdom of "Anonymous Monk" once again presents us with its graces.

        :-)

      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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2018-10-24 01:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...














    Results (127 votes). Check out past polls.

    Notices?