Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8848261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:23:03+00:00 2026-06-14T12:23:03+00:00

this is a part af my script that find a specific line that contain

  • 0

this is a part af my script that find a specific line that contain both $j[1] and $tt in a file.
in the foreach block the loop variable just take first four elements of @pdb file!!

here is the file :

REMARK   4
REMARK   4
ATOM      1  N   UNK     1      12.964  -9.630   0.000  1.00  0.00
ATOM      2  N   UNK     1      16.585  -9.566   0.000  1.00  0.00
ATOM      3  C   UNK     1      17.270 -10.706   0.000  1.00  0.00
ATOM      4  N   UNK     1      20.927 -10.960   0.000  1.00  0.00
ATOM      5  C   UNK     1      22.257 -10.919   0.000  1.00  0.00
ATOM      6  C   UNK     1      22.886  -9.747   0.000  1.00  0.00
ATOM      7  C   UNK     1      24.215  -9.706   0.000  1.00  0.00
ATOM      8  O   UNK     1      24.992  -8.627   0.000  1.00  0.00
ATOM      9  N   UNK     1      25.815 -10.400   0.000  1.00  0.00
ATOM     10  C   UNK     1      27.131 -10.205   0.000  1.00  0.00
ATOM     11  C   UNK     1      27.620  -8.968   0.000  1.00  0.00
ATOM     12  N   UNK     1      29.548  -8.236   0.000  1.00  0.00
ATOM     13  C   UNK     1      21.133 -12.275   0.000  1.00  0.00
ATOM     14  C   UNK     1      22.373 -12.754   0.000  1.00  0.00
ATOM     15  C   UNK     1      22.579 -14.068   0.000  1.00  0.00
ATOM     16  O   UNK     1      23.819 -14.547   0.000  1.00  0.00
ATOM     17  N   UNK     1      21.284 -14.374   0.000  1.00  0.00
ATOM     18  C   UNK     1      20.304 -15.273   0.000  1.00  0.00
ATOM     19  C   UNK     1      20.593 -16.571   0.000  1.00  0.00
ATOM     20  N   UNK     1      19.612 -17.470   0.000  1.00  0.00
ATOM     21  C   UNK     1      12.355  -8.448   0.000  1.00  0.00
ATOM     22  C   UNK     1      11.027  -8.383   0.000  1.00  0.00
ATOM     23  C   UNK     1      10.418  -7.201   0.000  1.00  0.00
ATOM     24  O   UNK     1       9.090  -7.136   0.000  1.00  0.00
ATOM     25  N   UNK     1      11.131  -6.078   0.000  1.00  0.00
ATOM     26  C   UNK     1      11.870  -4.972   0.000  1.00  0.00
ATOM     27  C   UNK     1      11.282  -3.779   0.000  1.00  0.00
ATOM     28  N   UNK     1      12.020  -2.673   0.000  1.00  0.00
ATOM     29  C   UNK     1      11.794 -10.263   0.000  1.00  0.00
ATOM     30  C   UNK     1      11.757 -11.593   0.000  1.00  0.00
ATOM     31  C   UNK     1      10.587 -12.226   0.000  1.00  0.00
ATOM     32  O   UNK     1      10.550 -13.555   0.000  1.00  0.00
ATOM     33  N   UNK     1       9.563 -11.377   0.000  1.00  0.00
ATOM     34  C   UNK     1       8.238 -11.495   0.000  1.00  0.00
ATOM     35  C   UNK     1       7.678 -12.701   0.000  1.00  0.00
ATOM     36  N   UNK     1       6.353 -12.819   0.000  1.00  0.00
TER      37      UNK     1
CONECT    1    2   21   29
CONECT    2    1    3
CONECT    3    2    4
CONECT    4    3    5   13
CONECT    5    4    6
CONECT    6    5    7
CONECT    7    6    8    9
CONECT    8    7
CONECT    9    7   10
CONECT   10    9   11
CONECT   11   10   12
CONECT   12   11
CONECT   13    4   14
CONECT   14   13   15
CONECT   15   14   16   17
CONECT   16   15
CONECT   17   15   18
CONECT   18   17   19
CONECT   19   18   20
CONECT   20   19
CONECT   21    1   22
CONECT   22   21   23
CONECT   23   22   24   25
CONECT   24   23
CONECT   25   23   26
CONECT   26   25   27
CONECT   27   26   28
CONECT   28   27
CONECT   29    1   30
CONECT   30   29   31
CONECT   31   30   32   33
CONECT   32   31
CONECT   33   31   34
CONECT   34   33   35
CONECT   35   34   36
CONECT   36   35
MASTER        3    0    0    0    0    0    0    0   36    1   36    0
END

and the perl script :

#!/bin/perl
use strict;
open(pdb,"den.pdb") or die "$!";

my @pdb=<pdb>;
my $n0="N";
my @aa;
my $temp;
my @n1_find;
foreach (@pdb) {
    #$_ as selected line in file
    print $_;
    my @j=split(/\s{1,}/,$_);
    #j : array that contain line elements> eg. j[0] REMARK, ATOM ,...
    if ($j[0] eq "HETATM" or $j[0] eq "ATOM") {
        #print @pdb;
        @aa=grep {/CONECT/ && /\s$j[1]\s/} @pdb ; # pattern that search for CONECT that first N involve in it
        if ($j[2] eq $n0) { # get another N ATOM
            foreach my $ii (splice(@pdb, $temp, $#pdb)) {
                if ($ii=~/$j[0]\s{1,}(\d+)\s{1,}$n0/i) { #search for lines that contain ATOM id "First N" and the second
                    my $tt=$1;
                    if (grep {/CONECT/ && /\s$tt\s/} @aa) { #save both N and exit
                        $n1_find[0]=$j[1];
                        $n1_find[1]=$tt;
                        #$temp=-1;
                    }
                }
            }
        }
    }
    #last if ($temp==-1) ;
    #print $temp+=1;
}

i placed a loop condition for exit but even when i remove it from script it don’t get all array variable.
ThanX.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:23:04+00:00Added an answer on June 14, 2026 at 12:23 pm

    You have several problems in your script. I won’t bother listing all of them in details: bad variable names, no comments, weird logic, no use strict;use warnings;, using insecure 2-argument form of open() and global file handle; not using proper CPAN modules (File::Slurp for file reading).

    • The main one is that your main loop uses a $_ default variable for looping that gets overwritten inside without being localized (e.g. by grep).

      Use an explicit loop variable: foreach my $line (@pdb) {

    • A secondary one is that you are looping over @pdb array, AND iterating over the same array within the loop (again using grep). it quite likely throws off the loop.

      Try to iterate over a copy of the array.

      my @pdb2 = @pdb;
      foreach my $line (@pdb2) {
      

    Once you make those 2 minor fixes, at the very least your script will iterate over ALL lines in the outer loop. Then you can start debugging actual logic inside the loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have part of my script that goes like this: while read line do
I found this script on pastebin that is an IRC bot that will find
I have a part of my script that does this: Removes everything in directory
I have this part of script from my GAE application which uses webapp2, which
I'm writing a ruby bootstrapping script for a school project, and part of this
This part of an app that I am working on, I have the following
This is part of my TV guide script: //Connect to the database mysql_connect(localhost,root,PASSWORD); //Select
I'm writing a perl script that mimics gcc. This my script needs to process
I'm working on a python script that opens a logfile, writes specific information to
I'm trying to write a script that will find a particular process based on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.