Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hi This is my 2nd perl program. I do not know all basics. I want some help with following progra. Any help is appreciated. I want to open two text files and grab two substrings in two opened files. I want to grab another value from first opened file as well. Now I want to print the value from first file repeatedly as long as the two substrings from two files match.I wrote some thing like this. The program i managed to write gives only one value from MYFILE and prints it repeatedly in the new file.
#!/usr/bin/perl -w use strict; #crappy open (MYFILE, "2hgs_d00_internal_nrg_e.dat"); our $nrgval = " "; our $chn = " "; our $count; #our $chn[$count]; our $count2; #our $chn2[$count2] our @nrg; open (NEWF, "2HGS_bio_conv-min_p.pdb"); our $toprint = " "; our $chn2 = " "; while (<MYFILE>) { chomp; # avoid \n at the end of each line if ($_ =~/ENERGY/){ for($count=1;$count<=1;$count++){ $chn = substr $_, 20, 3; $nrgval = substr $_, 35, 8; while (<NEWF>) { chomp; # avoid \n at the end of each line our $j = 0; our $i = 0; if ($_ =~/ATOM/){ for($count2=1;$count2<=1;$count2++){ $chn2 = substr $_, 23, 3; $toprint = substr $_, 0, 65; for($chn=1;$chn<=$chn2;$chn++){ if ($chn==$chn2){ print " $toprint $nrgval \n"; } } } } } } } } close (MYFILE); close (NEWF);

In reply to incrementing already existing file by wanttoprogram

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (4)
    As of 2018-11-20 07:43 GMT
    Find Nodes?
      Voting Booth?
      My code is most likely broken because:

      Results (220 votes). Check out past polls.