in reply to Reporting
Now I haven't actually benchmarked it, so I'm not sure about a speed increase, but in the actual flow of the program, provided the comments are there to describe whats going on, it makes it easier for me to follow later on, and the for (sort) {} block is just that little bit tighter without needing a split(/:/) in there...# a sample file, lets say a *really* long /etc/passwd file # with lines like root:x:0:0:Super User:/:/sbin/sh someone:x:45:14:Some One:/home/someone:/bin/csh sometwo:x:46:14:Some Two:/home/sometwo:/bin/ksh # Lets say im gonna sort on uid then gid, I'll do while (<IN>) { chomp; ($uid,$gid) = ( split(/:/) )[2,3]; push(@tosort, [$uid, $gid, $_]); } ... for ( sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @tosort ) { print "$_->[2]\n"; }
|
---|