in reply to Understanding split in a while loop

while (<PASSWD>) { my @passwds = split /:/, <PASSWD>; }

Note that you've used <PASSWD> twice. This will skip the even-numbered lines of the file, not the odd-numbered. This is because you read a second line from the file each time inside the loop, splitting on that value. Therefore, your first line that is read from the file (read into $_ in the while() loop) is more or less being discarded.

Replies are listed 'Best First'.
Re^2: Understanding split in a while loop
by ghenry (Vicar) on Feb 28, 2005 at 12:50 UTC

    I thought that was it. Thanks. So it discards the odd numbered ones, i.e. line 1 etc.

    Thanks.

    Walking the road to enlightenment... I found a penguin and a camel on the way..... Fancy a yourname@perl.me.uk? Just ask!!!

      It doesn't discard them; it places them into $_ but you ignore it.</pedant>