in reply to coding style suggestion: (...)[1] vs. [...]->[1]
I don't have time to test if this is faster but it will not create the intermediate array. It might be more memory efficient if $string is really huge. But it won't let you take a slice.use strict; my $string = "zero one two three"; my $offset = 1; my $regex = '[^\\s]+\\s+' x $offset . '([^\\s]+)'; print $string =~ /$regex/; __END__ one
update now that I think about it it might not be very efficient if both $string and $offset are huge because $regex will also be huge. Just TIMTOWTDI.
update 'doh! liz's way is even better.
--
flounder
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: coding style suggestion
by liz (Monsignor) on Sep 19, 2003 at 12:18 UTC |