[OT] Help with Perl Script
Dave Cross
davorg at gmail.com
Fri Apr 23 08:06:45 UTC 2010
On 21 April 2010 09:21, Dan Track <dan.track at gmail.com> wrote:
> Hi,
>
> I appreciate that this is off-topic and wholly understand if I don't
> get an answer, although one would really appreciate it if I do get an
> answer :)
>
> Basically to improve my perl scripting, I've given myself a challenge
> where I would like to order the users in the passwd file by uid,
You've already got plenty of good advice in this thread, but I thought
you might be interested in seeing just how short the program can be if
you use a lot of Perl's features.
#!/usr/bin/perl
use strict;
use warnings;
@ARGV = '/etc/passwd';
print sort { (split /:/, $a)[2] <=> (split /:/, $b)[2] } <>;
I probably wouldn't use something _quite_ this cryptic in production code.
Cheers,
Dave...
More information about the users
mailing list