[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] passwd file fwacking



On Thu, 13 Apr 2000, Bennett Todd wrote:

> 	my %passwd = map { $_->[0] => $_ } map { [ split /:/ ] }
> 		IO::File->new("<$passwd")->getlines;
> 	my %shadow = map { $_->[0] => $_ } map { [ split /:/ ] }
> 		 IO::File->new("<$shadow")->getlines;
> 	$passwd{$_}->[1] = $shadow{$_}->[1] for keys %passwd;
> 	print join(':', @{$_}) for values %passwd;

Here's another approach using s/// instead of split/join on the passwd
file:

    @ARGV = $shadow;
    my %shadow = map +(split /:/)[0,1], <>;
    @ARGV = $passwd;
    s/^([^:]+):[^:]+/$1:$shadow{$1}/, print while <>;

-- 
Neko





==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe