BUT I've been trying to find out why I'm getting warnings of "substr outside of string" from my code for about three hours now, so I'd be really grateful if someone could tell me what I'm doing wrong.
In this section of code, I extract two cartesian coordinates from two different files, save it to two arrays, and compute the distance between them for each pair of coordinates. The format of the two files is such that the coordinate values I need are bang in the middle of the file. Wait, here is the sample data:
HETATM 1562 O HOH 189 48.728 50.544 -16.104
HETATM 1563 O HOH 190 56.288 63.252 16.442
I'm new to perl and I'm used to use C, so I used a nested foreach loop.
I've read the manual, and I've hit search on both google and the Supersearch here. (I haven't waded through the entire mass in that, but I spent about half an hour trying).
The relevant bit of code:
foreach (@hlines) #each line from file1 was saved to this array. { $xh= substr $_,31,8; $yh= substr $_,40,8; $zh= substr $_,48,8; foreach $pline (@plines) #ditto, each line from file2 saved to this array { $x1= substr $pline,31,8; #using $_ here instead of $pline aborts execu +tion due to compile errors. $y1= substr $pline,40,8; $z1= substr $pline,48,8; $r2=((&square($xh-$x1))+(&square($yh-$y1))+(&square($zh-$z1))); $r=sqrt($r2); print "$i. $r2 and square root is $r\n"; } }
The warning shows up for the inner loop, and I'm using strict, subs, and warnings. This is perl v5.8.0 and I'm on a Red Hat 9.0 Linux system.
I don't understand why I'm getting the warning for the inner but not the outer loop.
The manual says that the warning means that I 'looking' outside the string for the substring. All those three substr in the inner loop have as many characters on either side of them as the outer loop substr. 56 char in a line of input, btw.
What am I missing here?
In reply to substr in nested foreach loop by sarani
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |