For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > February 2005 > Re: Understanding split in a while loop









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Understanding split in a while loop
Ankur Gupta

2005-02-28, 3:56 pm

>
>
>I am not sure why? It misses the odd ones.
>
>while (<PASSWD> ) {
>my @passwds = split /:/, <PASSWD>;
>

You are reading the file twice in each while loop. Whenever you access <PASSWD>, it returns a line and moves to the next line of the file.
So in "while (<PASSWD> ) {" it returns one line of the passwd file .
As you are reading the line again in "my @passwds = split /:/, <PASSWD>;", you are missing out on the previous line.

>print "@passwds";
>}
>


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com