clearly I'm not only bad at scripting but bad a posting! Give me a break! By the way, until about a week ago i had never heard of perl and had no idea whatsoever about computer programming so please be nice!! I am writing a script which will check the options for the following file, and if they are valid keep them if not delete them.
!# 23 ! 3 1 ! 9 10 37 ! 11 assign ( (resid 2 and name HB1) or (resid 2 and name HG) or (resid 7 and name HG11) ) ( (resid 2 and name HN) ) 0.0 1.8 3.00 ! 24 !# 25 ! 3 2 ! 9 10 37 ! 7 30 assign ( (resid 2 and name HB1) or (resid 2 and name HG) or (resid 7 and name HG11) ) ( (resid 2 and name HA) or (resid 6 and name HA) ) 0.0 1.8 4.07 ! 26
it works for the top example but not the bottom and I dont know why. ie we're comparing the combinations of f\2HA and 2HB1, 2HA and 2HG etc. The first example deletes the line with 7 in it as it should, while the second example deletes all the lines with twos even though they are valid. Here is the script
#!/usr/bin/perl $katfile = "/remote/belgarath/tpukala/pegasus/xplor/signif/25jun2.kat2 +" ; $outfile = "temp.kat"; open(OUTFILE, ">$outfile") or die "Can't open $outfile"; open(KATFILE, "$katfile") or die "Can't open $katfile"; @array = <KATFILE>; chomp @array; $numelements = @array; @arraylist=(0 .. $numelements); foreach $el (@arraylist) { if ($array[$el] =~ /^\)$/ && $array[$el+1] =~ /^\($/) { print(OUTFILE ")\n*\n*\n*\n*\n*\n*\n*\n") } elsif ($array[$el] =~ /assign/ && $array[$el+1] =~ /^\($/) { print(OUTFILE "assign\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n" +) } else { print(OUTFILE "$array[$el]\n"); } } close(KATFILE); close(OUTFILE); $distfile = "/remote/belgarath/tpukala/pegasus/xplor/signif/25jun/rnk_ +2 5jun_signif_.dst"; $katfile = "/remote/belgarath/tpukala/pegasus/xplor/signif/temp.kat"; $outfile = "temp2.kat"; open(OUTFILE, ">$outfile") or die "Can't open $outfile"; open(KATFILE, "$katfile") or die "Can't open $katfile"; @array2 = <KATFILE>; chomp @array2; $numelements2 = @array2; @arraylist2=(0 .. $numelements2); #************************** #************************** foreach $el (@arraylist2) { #************************** if ($array2[$el+10] =~ /resid (\d+) and name (H\w+\d*).?\)/ && $array2[$el] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $resid = $1; $atomid = $2; if ($array2[$el+10] =~ /resid (\d+) and name (H\w+\d*) +. ?\)/) { $residmatch = $1; $atomidmatch = $2; } open(DISTFILE, "$distfile") or die "Can't open $distfi +l e"; while (<DISTFILE>) { $line=$_; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } elsif($array2[$el+11] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+12] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+13] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+14] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+15] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } }} } #************************* elsif ($array2[$el+11] =~ /resid (\d+) and name (H\w+\d*).?\)/ && $array2[$el] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $resid = $1; $atomid = $2; if ($array2[$el+11] =~ /resid (\d+) and name (H\w+\d*) +. ?\)/) { $residmatch = $1; $atomidmatch = $2; } open(DISTFILE, "$distfile") or die "Can't open $distfi +l e"; while (<DISTFILE>) { $line=$_; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } elsif($array2[$el+12] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+13] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+14] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+15] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+16] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } }} } #************************* elsif ($array2[$el+12] =~ /resid (\d+) and name (H\w+\d*).?\)/ && $array2[$el] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $resid = $1; $atomid = $2; if ($array2[$el+12] =~ /resid (\d+) and name (H\w+\d*) +. ?\)/) { $residmatch = $1; $atomidmatch = $2; } open(DISTFILE, "$distfile") or die "Can't open $distfi +l e"; while (<DISTFILE>) { $line=$_; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } elsif($array2[$el+13] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+14] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+15] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+16] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+17] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } }} } #************************* elsif ($array2[$el+13] =~ /resid (\d+) and name (H\w+\d*).?\)/ && $array2[$el] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $resid = $1; $atomid = $2; if ($array2[$el+13] =~ /resid (\d+) and name (H\w+\d*) +. ?\)/) { $residmatch = $1; $atomidmatch = $2; } open(DISTFILE, "$distfile") or die "Can't open $distfi +l e"; while (<DISTFILE>) { $line=$_; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w+\s+$residmatch\s+$atomid.* \w+\s+$r +e sid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } elsif($array2[$el+14] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w+\s+$residmatch\s+$atomid.* \w+\s+$r +e sid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+15] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w+\s+$residmatch\s+$atomid.* \w+\s+$r +e sid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+16] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+17] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+18] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } }} } #************************* elsif ($array2[$el+14] =~ /resid (\d+) and name (H\w+\d*).?\)/ && $array2[$el] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $resid = $1; $atomid = $2; if ($array2[$el+14] =~ /resid (\d+) and name (H\w+\d*) +. ?\)/) { $residmatch = $1; $atomidmatch = $2; } open(DISTFILE, "$distfile") or die "Can't open $distfi +l e"; while (<DISTFILE>) { $line=$_; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w+\s+$residmatch\s+$atomid.* \w+\s+$r +e sid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } elsif($array2[$el+15] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w+\s+$residmatch\s+$atomid.* \w+\s+$r +e sid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+16] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w+\s+$residmatch\s+$atomid.* \w+\s+$r +e sid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+17] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+18] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+19] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } }} } #************************* elsif ($array2[$el+15] =~ /resid (\d+) and name (H\w+\d*).?\)/ && $array2[$el] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $resid = $1; $atomid = $2; if ($array2[$el+15] =~ /resid (\d+) and name (H\w+\d*) +. ?\)/) { $residmatch = $1; $atomidmatch = $2; } open(DISTFILE, "$distfile") or die "Can't open $distfi +l e"; while (<DISTFILE>) { $line=$_; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w+\s+$residmatch\s+$atomid.* \w+\s+$r +e sid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } elsif($array2[$el+16] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w+\s+$residmatch\s+$atomid.* \w+\s+$r +e sid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+17] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w+\s+$residmatch\s+$atomid.* \w+\s+$r +e sid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+18] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+19] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } } elsif($array2[$el+20] =~ /resid (\d+) and name (H\w+\d*).?\)/) { $residmatch = $1; $atomidmatch = $2; if (($line =~ /$atomid.*\s*\w+\s+$resid\s+$ato +m idmatch.* \w+\s+$residmatch\s+\d\./) || ($line =~ /$atomidmatch.*\s*\w ++ \s+$residmatch\s+$atomid.* \w+\s+$resid\s+\d\./)) { print(OUTFILE "$array2[$el]\n"); last; } }} } #************************* else { print(OUTFILE "$array2[$el]\n"); } } close(KATFILE); close(OUTFILE); #*************************** #*************************** $katfile = "/remote/belgarath/tpukala/pegasus/xplor/signif/temp2.kat"; $outfile = "half.kat"; open(OUTFILE, ">$outfile") or die "Can't open $outfile"; open(KATFILE, "$katfile") or die "Can't open $katfile"; @array3 = <KATFILE>; chomp @array3; $numelements3 = @array3; @arraylist3=(0 .. $numelements3); foreach $el (@arraylist3) { if($array3[$el] =~ /^\*$/) { } elsif($array3[$el] eq $array3[$el+1]) { } else { print(OUTFILE "$array3[$el]\n"); } } #end

In reply to nmr comparison script by NMRsucks

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.