Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: substr in nested foreach loop

by Jasper (Chaplain)
on May 22, 2006 at 17:09 UTC ( #550982=note: print w/replies, xml ) Need Help??

in reply to substr in nested foreach loop

The problem is that this line :

HETATM 1562 O HOH 189 48.728 50.544 -16.104

is only 43 characters long, and you're doing $zh= substr $_,48,8; on it. That takes the 48th through to the 55th characters and sticks them in a string. Read the error message with this in mind, and see if you can work it out :)

Replies are listed 'Best First'.
Re^2: substr in nested foreach loop
by sarani (Sexton) on May 23, 2006 at 04:02 UTC
    There are whitespaces on either side, and length gives 57. The file is formatted such that except for the last line, each line has that many chars. :) That's the cause of my confusion.
      Yeah but no but yeah.

      If you stick a warning before each substr operation giving the length of the string and which characters it's trying to find, I bet you'll trace the problem pretty quickly.
        Jasper: Yeah, I got it. *sheepish grin* End of line char at the end of file. Thanks. :)

        Oh, and a couple of places where the file formatting was irregualr because of overwriting. *feels dumb*

        On the positive side, I've learnt more in the time it took me to read this thread and attempt to implement all of the suggestions (I did) than I did while trying to debug all by myself...So I owe all the Monks who were kind enough to reply a huge thanks.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://550982]
[erix]: average between 1 and 20
[erix]: ( median troll aka 'the bird' )

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2018-06-21 16:34 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (118 votes). Check out past polls.