- or download this
my $str = `who`;
- or download this
foreach my $line (split /\n/,$str) {
my ($user, $remainder) = split /\s/,$_,2;
$hash{$user}++; # just increment the value
}
- or download this
open(PIPE,"who |") or die "Can't run 'who': $!\n";
while(<PIPE>) {
my ($user, $remainder) = split; # implicit split splits $_ on /\s
++/
$hash{$user}++;
- or download this
# sort by user
foreach my $user(sort keys %hash) {
...
foreach my $user(sort {$hash{$a} <=> $hash{$b}} keys %hash) {
print "$user logged in $hash{$user} times.\n";
}