I noticed a couple areas where yours could be improved efficiency wise and one potential bug:
That is a big improvement, especially fixing the bug. The redo instead of goto is so obvious ... yet I didn't see it.
I'm definitely a fan of jaredor's solution below
Me too. At least, jaredor's second solution. Which I'd missed till now.
I did see his original solution and my eyes zeroed in on this line:
my @sg = sort {$a<=>$b} uniq grep {defined} (@v2g{@$i}, min @$i);
There's a lot of potentially expensive processing going on in that one line. Repeating that every time around the outer loop of a large set of data smacked of "expensive".
By contrast, his second solution is almost magical in its simplicity and deserves elevating to tutorial.
I wouldn't mind betting that many of the graphing packages (and their authors) could learn a lot from that unremarkable looking piece of code.
then realized that there didn't need to be an identified element per subgraph...
Don't you just love understatement :)
In reply to Re^3: how to find combine common elements of an array?
by BrowserUk
in thread how to find combine common elements of an array?
by ihperlbeg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |