Re: [OT] Help with Perl Script

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

 



On Wed, Apr 21, 2010 at 4:41 PM, Norman Gaywood <ngaywood@xxxxxxxxxx> wrote:
> On 22 April 2010 01:26, Norman Gaywood <ngaywood@xxxxxxxxxx> wrote:
>> On Wed, Apr 21, 2010 at 04:12:06PM +0100, Dan Track wrote:
>>> On Wed, Apr 21, 2010 at 1:30 PM, Norman Gaywood <ngaywood@xxxxxxxxxx> wrote:
>>> > On Wed, Apr 21, 2010 at 09:21:30AM +0100, Dan Track wrote:
>>> >> hashes. It's after this that I'm stuck, I'm struggling to order the
>>> >> hash of hashes by uid and then print the ordered list out? Can someone
>>> > [snip]
>>> >> foreach my $sorted ( sort { $HoH->{$a}{uid} cmp $HoH->{$b}{uid} } keys %HoH)
>>> >
>>> > cmp is a string comparison. You probably want to sort numerically on the
>>> > uid. So replace 'cmp' with '<=>'
>>
>>> foreach my $sorted ( sort { $HoH{$a}->{"uid"} <=> $HoH{$b}->{"uid"} } keys %HoH)
>>> {
>>> print STDOUT "$HoH{$sorted}\n"
>>> }
>>
>>> and all I get out is:
>>>
>>> perl sort.pl
>>> HASH(0x89de3d0)
>>> HASH(0x8a05d40)
>> [snip]
>>
>> $HoH{$sorted} is a reference to a hash. $HoH{$a}{uid} (or in
>> long hand $HoH{$a}->{"uid"}) should print out the uid numbers.
>
> That should be $HoH{$sorted}{uid}
>
> --
Fantastic, you're a star :)

One last point how can I print all the associated deatils attached to
that uid i.e username, home dir etc and then cycle through for every
uid and print the same information for each respective uid? The uid's
need to be in order i.e something like

uid: 0, username: root etc...
uid 50, username: mysql etc...


Many many thanks
Dan
-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux