From: "Gavin Henry" <[EMAIL PROTECTED]>
> Just a quickie. I think the answer is that th while loop is going
> through the file twice?

Nope
 
> --------------
> Codes that does what I expect, i.e. prints out the 42 lines of my
> passwd file, with the array spaces, due to the array in "", swapped
> for <was :> and runs on $_:
> 
> #!/usr/bin/perl
> use strict;
> use warnings;
> 
> $" = '<was :>';
> 
> open PASSWD, "/etc/passwd"
>   or die "Eh? ($!)";
> 
> while (<PASSWD>) {

The line above reads one line from the PASSWD handle and puts the line into $_.

> my @passwds = split /:/;

This line splits the $_ variable by colons and puts the items into 
@passwds.

> 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>) {

The line above reads one line from the PASSWD handle and puts the 
line into $_.

> my @passwds = split /:/, <PASSWD>;

And this line reads another line from PASSWD, splits it by colons and 
puts the items into the @passwds array.

> print "@passwds";
> }

HTH, Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to