Re: HTML::Parser - newbie question

Randal Schwartz (merlyn@stonehenge.com)
05 Jul 1998 08:58:11 -0700


I know you didn't ask for a code review, but some of this stuff
looked a little scary, and I want to make sure that the next
person down doesn't use them as templates for *their* code,
so here goes...

>>>>> "David" == David Baron <davidb@versaware.com> writes:

David> sub InList {
David> 	my ( $tag, @list ) = @_;

David> 	my $ret = grep (/^$tag$/i, @list );
David> }

This is a FAQ, but if you can't pre-cache a hash with static keys, you
can at least speed this up with:

	scalar grep $_ eq $tag, @list;

David> sub Ieq {
David> 	my ( $string1, $string2 ) = @_;

David> 	return ( $string1 =~ /^$string2$/i );
David> }

And you can get a big speedup on this one by again avoiding regex:

	lc $string1 eq lc $string2;

David> sub Last {
David> 	my ( @array ) = @_;
David> 	my $nItems = @array;

David> 	return $nItems > 0
David> 		? $array [ $nItems - 1 ]
David> 		: undef;

David> }

And I'd just inline this one as:

	$array[-1]

David> sub Redir {
David> 	my ( $directory, $subdirectory, $oldpath ) = @_;

And most of this looks like it could be built on File::Basename,
included in the standard distribution, and handles Mac and VMS paths
as well as DOS/unix paths.

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me