in reply to How do remove trailing data?
My opinion, regex is overkill for such situations. Might be the developers considered all situations, and made regex handle the situation efficiently, but it just seems wrong.
Efficient and simple: split on the # and take the first component:
my $url = ( split '#', $urlplusplus )[0]
or use index() to find where the # is, and use substr to fetch the prefix.
my $url = substr $urlplusplus, 0, index( $urlplusplus, '#' );
Of course, benchmark might provide some surprises.
As Occam said: Entia non sunt multiplicanda praeter necessitatem.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How do remove trailing data?
by JavaFan (Canon) on Dec 24, 2010 at 14:23 UTC | |
|
Re^2: How do remove trailing data?
by ww (Archbishop) on Dec 24, 2010 at 13:53 UTC |