in reply to Re: Re: Re: Re: Re: Reducing a line read into $_
in thread Reducing a line read into $_

I'd be interested in hearing why you think your solution is better than ^\[.*?\]. I think that the non-greedy "?" eliminates all of the potential .* issues in this case.

Of course, I haven't benchmarked the solutions yet.

--
<http://www.dave.org.uk>

"Perl makes the fun jobs fun
and the boring jobs bearable" - me

  • Comment on Re: Re: Re: Re: Re: Re: Reducing a line read into $_

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Re: Reducing a line read into $_
by repson (Chaplain) on Jan 04, 2001 at 17:42 UTC
    I'm not sure how the benchmarks would actually be, I'm speaking more from my understanding of other people's explanations of how they work (probably wrong).
    • \[.*?\] - starting at the first [ look at up all sizes of .*? from the longest to the shortest, then for which ones are followed by a ], choose the shortest one.
    • \[[^\]]*\] - starting at the first [ search through all possible [^\]]* from shortest to longest, until we find an ], at that point choose the previous one.
    Or something like that. I think I find the second logic to make more sense to me.

    Update: and the other point is I'm suggesting avoiding the habit of overusing the dot, which can cause problems such as were addressed in the thread I linked.