[vox-tech] Matching Contents of Lists

Micah J. Cowan micah at cowan.name
Fri Jul 8 12:46:14 PDT 2005


On Fri, Jul 08, 2005 at 01:52:38PM -0500, Jay Strauss wrote:
> sub parse {
> 	my $str = $_[0];
> 
> 	# Capture the parts, leading alpha, followed by n digits,
> 	# followed optionally by alphas
> 	$str =~ /([a-zA-Z]+)(\d+)([a-zA-Z]+)?/;
> 	
> 	my @str = ($1,$2,$3);	# put the matches back into an array

Of course, this could have been:

  my (@str) = $str =~ /([a-zA-Z]+)(\d+)([a-zA-Z]+)?/;

eliminating the need to refer specifically to the positional variables.

> 	$str[1] =~ s/^0+//;     # strip leading 0s from digit portion

Personally, I typically use $str[1] += 0, but obviously that's a style
thing.
> 
> 	return @str;
> }

-- 
Micah J. Cowan
micah at cowan.name


More information about the vox-tech mailing list