in reply to counter of files? something else?
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 :'(
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: counter of files? something else?
by soonix (Chancellor) on Apr 23, 2015 at 13:19 UTC | |
by fasoli (Beadle) on Apr 23, 2015 at 13:40 UTC | |
|
Re^2: counter of files? something else?
by Random_Walk (Prior) on Apr 23, 2015 at 13:29 UTC | |
by fasoli (Beadle) on Apr 23, 2015 at 13:49 UTC |