Xref: utzoo alt.sources:1552 comp.lang.perl:526 Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!mailrus!wuarchive!brutus.cs.uiuc.edu!jarthur!elroy.jpl.nasa.gov!jato!lwall From: lwall@jato.Jpl.Nasa.Gov (Larry Wall) Newsgroups: alt.sources,comp.lang.perl Subject: Re: Version of id(1). Message-ID: <2969@jato.Jpl.Nasa.Gov> Date: 2 Mar 90 22:50:23 GMT References: <426@clover.warwick.ac.uk> <2964@jato.Jpl.Nasa.Gov> <1990Mar2.210209.11209@iwarp.intel.com> Reply-To: lwall@jato.Jpl.Nasa.Gov (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 33 In article <1990Mar2.210209.11209@iwarp.intel.com> merlyn@iwarp.intel.com (Randal Schwartz) writes: : In article <2964@jato.Jpl.Nasa.Gov>, lwall@jato (Larry Wall) writes: : [21 lines of code deleted...] : | No doubt Randal could write it shorter... : : Well, OK, taking on the challenge, how about: : : #!/usr/bin/perl : sub u { local($name)=getpwuid($_[0]); $name && "($name)";} : sub g { local($name)=getgrgid($_[0]); $name && "($name)";} : sub bynum { $a - $b; } : print "uid=$<",&u($<); : print " gid=", $(+0,&g($(); : print " euid=$>",&u($>) if $> != $<; : print " egid=", $)+0,&g($)) if $) != $(; : @groups=split(' ',$(); shift(@groups); : print " groups=", join(',',sort bynum grep(($_ .= &g($_)) || 1, @groups)) : unless $#groups < $[; : print "\n"; : : Something like that, Larry? That's not short. This is short: :-) #!/usr/bin/perl @n=('pwu','grg');sub n{local($n)=eval"get$n[$_[1]]id(\$_[0])";$n&&"($n)";}sub nm {$a-$b;}@gr=split(' ',$();$g=shift(@gr);$\="\n";print"uid=$<",&n($<)," gid=",$g, &n($(,1),(" euid=$>".&n($>))x($),(" egid=".$)+0 .&n($),1))x($(!=$)), (" groups=".join(',',sort nm grep(($_.=&n($_,1))||1,@gr)))x($#gr>=0); Though I'll admit readability suffers slightly... Larry