Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Hello im new to programming i need help

by fahadm89 (Initiate)
on Feb 10, 2013 at 01:17 UTC ( [id://1018006]=note: print w/replies, xml ) Need Help??


in reply to Re: Hello im new to programming i need help
in thread Hello im new to programming i need help

Here is what i just tried

#!/usr/bin/perl -w $dir = "/net/klab2/u2/home/fmohammad/GFP2/run1"; opendir (DIR, $dir) or die $!; @one = readdir (DIR); foreach $file (@one) { $initialfile2 = "$file"; open FILETWO, "$initialfile2" or die "cannot open $initialfile +2 for read\n"; while ($line2 = <FILETWO>) { chomp $line2; @one=split(/\s+/, $line2); if ($one[0]=~m/^HETATM/) { if ($one[2]eq "C4") { $xC4=$one[6]; $yC4=$one[7]; $zC4=$one[8]; } if ($one[2]eq "C1") { $xC1=$one[6]; $yC1=$one[7]; $zC1=$one[8]; } if ($one[2]eq "C13") { $xC13=$one[6]; $yC13=$one[7]; $zC13=$one[8]; } } } close FILETWO; $initialfile = "1GFL.pdb"; open FILEONE, "$initialfile" or die "cannot open $initialfile +for read\n"; while ($line = <FILEONE>) { chomp $line; @two=split(/\s+/, $line); if ($two[0]=~m/^ATOM/) { if ($two[1]eq "479") { $xS=$two[6]; $yS=$two[7]; $zS=$two[8]; } if ($two[1]eq "484") { $xY=$two[6]; $yY=$two[7]; $zY=$two[8]; } if ($two[1]eq "496") { $xG=$two[6]; $yG=$two[7]; $zG=$two[8]; } } } close FILEONE; $part1 = ((($xC1 - $xS)**2) + (($yC1 - $yS)**2) + (($zC1 - $zS +)**2)); $part2 = ((($xC4 - $xY)**2) + (($yC4 - $yY)**2) + (($zC4 - $zY +)**2)); $part3 = ((($xC13 - $xG)**2) + (($yC13 - $yG)**2) + (($zC13 - +$zG)**2)); $sum = $part1 + $part2 + $part3; $sum1 = $sum / 3; $rmsd = sqrt ($sum1); print"$rmsd\n"; }

and here is the error:

Use of uninitialized value $xC1 in subtraction (-) at getrmsd2.pl line + 80. Use of uninitialized value $yC1 in subtraction (-) at getrmsd2.pl line + 80. Use of uninitialized value $zC1 in subtraction (-) at getrmsd2.pl line + 80. Use of uninitialized value $xC4 in subtraction (-) at getrmsd2.pl line + 81. Use of uninitialized value $yC4 in subtraction (-) at getrmsd2.pl line + 81. Use of uninitialized value $zC4 in subtraction (-) at getrmsd2.pl line + 81. Use of uninitialized value $xC13 in subtraction (-) at getrmsd2.pl lin +e 82. Use of uninitialized value $yC13 in subtraction (-) at getrmsd2.pl lin +e 82. Use of uninitialized value $zC13 in subtraction (-) at getrmsd2.pl lin +e 82. 70.8509364158301 Use of uninitialized value $xC1 in subtraction (-) at getrmsd2.pl line + 80. Use of uninitialized value $yC1 in subtraction (-) at getrmsd2.pl line + 80. Use of uninitialized value $zC1 in subtraction (-) at getrmsd2.pl line + 80. Use of uninitialized value $xC4 in subtraction (-) at getrmsd2.pl line + 81. Use of uninitialized value $yC4 in subtraction (-) at getrmsd2.pl line + 81. Use of uninitialized value $zC4 in subtraction (-) at getrmsd2.pl line + 81. Use of uninitialized value $xC13 in subtraction (-) at getrmsd2.pl lin +e 82. Use of uninitialized value $yC13 in subtraction (-) at getrmsd2.pl lin +e 82. Use of uninitialized value $zC13 in subtraction (-) at getrmsd2.pl lin +e 82. 70.8509364158301 1.68309110468408

Replies are listed 'Best First'.
Re^3: Hello im new to programming i need help
by jethro (Monsignor) on Feb 10, 2013 at 02:11 UTC

    Well, this means that for example the variable $xC1 didn't get set to any value when you use it in line 80. Now lets look at the lines where you want to set the variable. It is in a part that is executed only when two if-clauses are true.

    The warnings indicate that all variables that depend on the outer if-clause "if ($one[0]=~m/^HETATM/)" have the same problem. So this if-clause probably is never true for at least the first two executions of the outermost loop i.e. for the first two files (and it seems from your test output that there is a third file where the if-clause is successfully run through). Because of that the variables are empty and you get the warnings.

    So you have to change your script so that when the information you seek is not in the file the rest of the loop isn't executed anymore.

    For example:

    foreach $file (@one) { my $allfound=0; ... if ($one[2]eq "C4") { $allfound&=1; $xC4=$one[6]; $yC4=$one[7]; $zC4=$one[8]; } if ($one[2]eq "C1") { $allfound&=2; $xC1=$one[6]; $yC1=$one[7]; $zC1=$one[8]; } if ($one[2]eq "C13") { $allfound&=4; $xC13=$one[6]; $yC13=$one[7]; $zC13=$one[8]; } } } close FILETWO; next if ($allfound!=7);

    I'm using the first three bits in the variable $allfound to tell me if all if-clauses where run through at least once for this file.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1018006]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-19 20:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found