Saved has asked for the wisdom of the Perl Monks concerning the following question:
The commented out code works, but the modification to source the array from /etc/passwd fails. Is it the line feeds? how would I remove them? Or is there a better way. All help appreciated. Thanx#!/usr/bin/perl -w #<SortPW2.pl> /etc/passwd sort by UID $file="/etc/passwd"; my @array = do { local( @ARGV, $/ ) = $file ; <> } ; #my @array = ( #'555900:user:lee:0:23030', #'3520916:user:joe:0:20487', #'395284:user:richard:3:17557', #'807060:group:smith:0:20573', #'381940:home:kimble:1:625', #); my @sorted = map {$_->[0]} sort {$a->[1] <=> $b->[1] || $a->[1] cmp $b->[1]} map {[$_,(split':')[0]]} @array; print "$_\n" for @sorted;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sort passwd by UID
by moritz (Cardinal) on Apr 06, 2011 at 12:46 UTC | |
by Saved (Beadle) on Apr 06, 2011 at 13:08 UTC | |
|
Re: Sort passwd by UID
by toolic (Bishop) on Apr 06, 2011 at 12:49 UTC |