Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^3: string value assignment

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


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

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


Comment on Re^3: string value assignment
Re^4: string value assignment
by abidq (Initiate) on May 14, 2011 at 11:57 UTC
    #!/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.

        Whilst awaiting your reply, I thought I'd take a moment and try to help you understand some of the social missteps you've taken in this message thread. Please take these comments as attempts to help you see how you are perceived and not as a personal attack. They are designed solely to permit you to adjust your behavior IF YOU WANT TO, and are neither authoritative nor authoritarian. I am genuinely trying to help you, and if the advice is unwanted, the most graceful thing to do is to silently ignore my observations and advice.

        1. Posting anything but a short phrase in all caps is generally interpretted as yelling. Nobody likes to be yelled at, so it is inadvisable, especially when you are, in general, asking for help. I acknowledge the very real possibility you were simply trying to make your comments distinct from the Perl code, but that's not generally how it is perceived by your audience. Since you are the one seeking assistance, it is wise to know your audience, and address them the way they wish to be addressed. I have heared heard this concept summarized as "Speaking to the listening", and it is a wisdom I wished I'd accepted and adopted much, much earlier in my own Life. I find it useful to avoid using all caps except as emphasis for a word or a short phrase.
        2. This was awkward: "THATS ALL I WANT.....PLEEEZ HELP DEARS". I suspect you were trying to be cute, or friendly, or something along those lines. I also suspect a cultural or linguistic translation problem, where this might be a literal translation of something you might say natively to good effect.

          Unfortunately, I think most people are inclined instead to interpret this as an attempt to be ingratiating and manipulative.

          Though it is wise to show humility when seeking assistance, and to adopt the posture of a student who is addressing a teacher (regardless of the actual relationship or lack thereof), there's an odd social balance point for this. Too much demonstration of humility, and it starts to sound like either wheedling or manipulation. Too little demonstration of humility, and it sounds haughty, arrogant, and pushy. There is a grace required to find that middle ground, and it is more difficult in writing since the facial expressions, body language, and tones of voice are all missing -- typical problems for E-mail and related media. Nonetheless, it is wise to find that balance point, and respectfully request assistance when it is needed and then be on your way with whatever your goals are once you've gotten what you need.

        3. You were fairly consistently asked to supply the code you'd tried, and to your credit, you finally did supply it. I'll admit I'm too lazy to examine the timestamps on all the messages and examine everything in time sequence, but based on the threaded display, it seems like it might have taken you a few rounds of conversation to finally post some code.

          Regardless of whether that's actually what happened, it is wise to pay attention to any clues you get when seeking assistance. If almost everyone asks you to do something as part of their answer to your request, you can rest fairly well-assured that your best answers are going to come only after you comply with that oft-repeated request. You don't have to understand why it is needed, but you should be intelligent enough to see that everyone who is responding is requesting it, and wise enough to comply.

          This is a general statement; it does not apply simply to you. In some ways, I am writing this rambling diatribe to help anyone else who stumbles across this thread in the future, in case they don't understand this fairly basic concept. THE WORLD DOES NOT EXIST TO SERVE YOU. When you ask for help, the wisest way to ask for it is with humility. It is no loss to you, for a moment, to admit that someone else is better than you in some small way -- and if they teach you what they know, they will no longer be better than you in this way. So honor their status as teacher for a brief moment, and quite often, the teacher will give you more than the handful of rice for which you asked. You will often find that teachers, who teach because they find value in sharing their information, knowledge, and experience with others, want to transfer not just knowledge, but also understanding. But if you treat them with disdain, they will quite commonly (and, in my opinion, quite accurately) deduce that you are not worthy of the understanding, and may at best share only the knowledge. Often they will simply ignore you. But treat them with respect, and they will often give you the world.

        4. As far as I can see in this particular instance, the basic failing point is that you, like all of us, have assumptions about how some of Perl's mechanisms work, but not having used them before, some of your assumptions may be incorrect. This is extremely common for people new to writing software, and even somewhat common, though notably less so, for people learning a new software language.

          For some reason, we humans have a tendency to forget how we breached those obstacles in our own early days as software developers. Worse, some of us didn't have to overcome them as the concepts appeared as natural as breathing. So getting irritated responses is common when a newbie comes along and asks questions full of inaccurate assumptions. But don't worry about it. Ask your questions, remember your graces whilst doing so, and, as the old saying goes, "When the student is ready, the teacher will appear."

        Again, none of this is meant as a slam towards you specifically. I truely hope I have made clear that I understand your intentions were probably honest, and that many of the problems may lie in lack of experience with crossing cultural or linguistic boundaries.

        But if you master the grace I have described above (and I admit, much of it you probably already knew), I suspect you will find that aid comes to you as quickly and easily as you ask for it most of the time.

        And if I'm wrong, then at least I got to ramble on for a bit. :-) We old-timers like to do that from time to time.

        So, anyway -- back to waiting for your reply so we can get you past this challenge and on to solving bigger and better problems in the world.

Re^4: string value assignment
by Anonymous Monk on May 14, 2011 at 12:11 UTC
    we cant solve it

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

      :-)

Re^4: string value assignment
by abidq (Initiate) on May 14, 2011 at 16:40 UTC
    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

Re^4: string value assignment
by abidq (Initiate) on May 14, 2011 at 16:45 UTC
    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. :-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2014-12-21 12:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (104 votes), past polls