Hello Group,

 

I am trying to get this code to run. I got it from the book Data Munging with Perl. I 
cut and pasted the code, then changed the input from stdin to FILE. I supplied a text 
file for the passwords (I am on a Windows 2k box). But I can't get it correct. I think 
the line @[EMAIL PROTECTED]) = split(/:/); is incorrect syntactically but I could be 
wrong. Could anyone help me understand this problem. Thanks in Advance!

 

 

#!/perl -w

use strict;

use warnings;

 

open(FILE, "passwords.txt") or die("cant open file");

 

#read_passwd;

 

sub read_passwd {

 

my %users;

my @fields = qw/name pword uid gid fullname home shell/;

 

while (<FILE>) {

chomp;

my %rec;

@[EMAIL PROTECTED]) = split(/:/);

$users{$rec->{name}} = \%rec;

}

return \%users;

 

}

 

 

my $users = read_passwd();

 

my @names;

 

foreach (keys %{$users}) {

 

    next unless $users->{$_}{fullname};

 

    my ($forename, $surname) = split(/\s+/, $users->{$_}{fullname}, 2);

 

    push @names, "$surname, $forename";

  }

 

  print map { "$_\n" } sort @names;


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