ghenry has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
Just a quickie. I think the answer is that the while loop is going through the file twice?
--------------
Code that does what I expect, i.e. prints out the 42 lines of my passwd
file, with array spaces swapped for <was :>
and runs on $_:
#!/usr/bin/perl use strict; use warnings; $" = '<was :>'; open PASSWD, "/etc/passwd" or die "Eh? ($!)"; while (<PASSWD>) { my @passwds = split /:/; print "@passwds"; }
--------------
This now only prints 21 lines?
I am not sure why? It misses the odd ones.
#!/usr/bin/perl use strict; use warnings; $" = '<was :>'; open PASSWD, "/etc/passwd" or die "Eh? ($!)"; while (<PASSWD>) { my @passwds = split /:/, <PASSWD>; print "@passwds"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Understanding split in a while loop
by saskaqueer (Friar) on Feb 28, 2005 at 12:46 UTC | |
by ghenry (Vicar) on Feb 28, 2005 at 12:50 UTC | |
by Fletch (Bishop) on Feb 28, 2005 at 13:54 UTC |