in reply to A simple grouping of list items
What the heck, just for fun, some minor code changes for faster execution.
caveat: not tested, not benchmarked, maybe not even syntactically correct, could cause different output :)
my $previous = ""; # skip $item variable # 'for' just looks funny in this use foreach (@list) { # regex once instead of twice # no extra work shuffling $previous back and forth until needed if (m/^(.+)\: .+/ and $1 ne $previous) { $previous = $1; # take the sleep hit on the first item to save time later # (maybe even 5 seconds worth if you have a lot of items) sleep(5); } print $_; }
In Section
Cool Uses for Perl