in reply to Stupid, yet simple, sort question

this is most all of what it does:
require "config.txt"; $refresh="60"; $ip=$ENV{'REMOTE_ADDR'}; $time=time; open(FILE,$log); flock (FILE,3); @users=<FILE>; close(FILE); foreach $lines (@users){ chop($lines); ($ips,$times,$locationold)=split('×',$lines); $timeoff=$time-$times; push @locations,$locationold if (!$exists{$locationold}); $exists{$locationold}=1; ${$locationold}{online}++; foreach $loc (@locations){ if(${$loc}{online} < "2") { ${$loc}{users} = "user"; } else { ${$loc}{users} = "users"; } } foreach $loc (@locations){ print "${$loc}{online} ${$loc}{users} $loc\n"; }

Replies are listed 'Best First'.
Recode
by joealba (Hermit) on Oct 24, 2001 at 21:16 UTC
    require "config.txt"; my $refresh="60"; my $ip=$ENV{'REMOTE_ADDR'}; my $time=time; open(FILE,$log) or die "Couldn't open $log: $!\n"; flock (FILE,3); my @users=<FILE>; close(FILE); my %pages; foreach my $line (@users){ chomp($line); my ($ips,$times,$location)=split('×',$line); $pages{$location}++; } foreach my $loc (sort {$pages{$b} <=> $pages{$a}} keys %pages) { my $s = "s" unless $pages{$loc} == 1; print "$pages{$loc} user$s accessing $loc\n"; }
Unrelated style nits
by Fletch (Bishop) on Oct 24, 2001 at 21:12 UTC

    Always check the return value from things such as open and flock. And it'd be better to use the symbolic constants from Fcntl rather than hardcoding `3' (assuming traditional values that would seem to be LOCK_SH|LOCK_EX, which doesn't make much sense).