Thank you all for your feedback. I really appreciate it. Let me be a bit more clear (hopefully..) about what I want to do.

Here is a part of what I've written so far

#count the files in my foreach loop (I'm in a foreach loop, #not shown, that loops through @files my $count = @files; my @count = (); # I'l explain what I want to do with this - Note 1. push (@count, $count); print $count; print "\n"; #now this is where I am creating my new files, getting data from the #files in the foreach loop my $pdb; open (my $pdb, '>', "$filename.pdb"); my $p; my $w; my $title = "$filename"; my $bx = 50.000; my $by = 50.000; my $bz = 50.000; printf $pdb "%s$title"; printf $pdb "\n"; printf $pdb ("%5d",$atomcount); printf $pdb "\n"; for ($p=1; $p<=$atomcount; $p++) { my $carboxyl = "@count[$w]"; #here is all that I want to do-Note 2 printf $pdb("%5d%-5s%5s%5d%8.3f%8.3f%8.3f",1,$carboxyl,@atom[$p],$ +p,@x[$p],@y[$p],@z[$p]); printf $pdb "\n"; } printf $pdb("%10.5f%10.5f%10.5f",$bx,$by,$bz); printf $pdb "\n"; close $pdb/;

Note 1: My idea is that I'll first count the files I'm looping through (they're 40) and then I'll be able to tell perl to show me the first file (that is file 1), then the second file (file 2), all the way until 40. That's why I'm putting $count in an array, in order to tell perl "ok now show me the first time you find this type of file; then the second time and so on". That way... (takes us to note 2)

Note 2: ...I will be able to get this $carboxyl entry unique every time. In the first pdb file it will be equal to 1, then 2, up to 40. So I will never have two same $carboxyl values in any of my pdb files. That way I will be able to distinguish between them by looking at the contents: the first one will have $carboxyl = 1 all the way down (250 lines), the second one will have $carboxyl = 2 all the time and so on.

The problem is that I'm doing it wrong because obviously I'm just printing the actual count number. Also I think the approach is wrong, because it might be better to actually assign numbers to $carboxyl based on how many pdb files I open and create, that would make more sense, right? Rather than how many files I loop through to get data FOR the pdb file I'll create later.

Am I at least getting close in terms of understanding this? I know I have to do reading - I already have two books (Learning Perl and Beginning Perl) and opened all the links you've recommended (in order to read, not just to close them back). I'm panicking though because this will take me days to correct - been trying since yesterday for a simple counter thing :'(


In reply to Re: counter of files? something else? by fasoli
in thread counter of files? something else? by fasoli

Title:
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, details, 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, summary, 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.