Timeline for Find common preamble of a list of strings
Current License: CC BY-SA 3.0
6 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Dec 17, 2013 at 15:38 | vote | accept | Fozi | ||
Dec 10, 2013 at 21:06 | comment | added | Fozi | Something like this: ideone.com/WvVX86 updating question... | |
Dec 10, 2013 at 21:01 | comment | added | Fozi |
Thanks for your answer. Performance is an issue here, that's why I used substr and ne instead of index . However your answer made me realize that I don't need to preserve $a and $b (this is not a for loop) so I'm thinking of chopping both to size and compare them instead of using substr . Since $a is unlikely to change after line 2 I don't mind to have two chop s in the loop body...
|
|
Dec 10, 2013 at 20:47 | comment | added | amon |
@200_success You have a point there (even after a match failure, other positions are searched), and we could use until($current_prefix eq substr $string, 0, length $current_prefix) or until (0 == rindex $string, $current_prefix, 0) to get around that. My answer only optimized for readability, not for performance.
|
|
Dec 10, 2013 at 20:41 | comment | added | 200_success |
until (0 == index $string, $current_prefix) is likely to perform worse than the original.
|
|
Dec 10, 2013 at 20:36 | history | answered | amon | CC BY-SA 3.0 |