Re: Regex confusion...



_
sln@xxxxxxxxxxxxxx (sln@xxxxxxxxxxxxxx) wrote on VCXLI September MCMXCIII
in <URL:news:fnmof355vp963ba7occdgmgm9o3pc4ht4n@xxxxxxx>:
-- On Fri, 28 Sep 2007 00:10:42 +0100, Ben Morrow <ben@xxxxxxxxxxxx> wrote:
--
-- >
-- >This can be simplified to
-- >
-- > if (
-- > my ($t, $zip, $type) =
-- > $img =~ /^(\d)-(\d+)-(\w+)$/
-- > ) {
-- >
-- >which avoids the need to use the $N variables altogether.
-- >
--
-- It might be quicker to check for sucess first then do the asignment
--
-- $_ = "......";
-- if ( /^(\d)-(\d+)-(\w+)$/ )
-- {
-- #use $1,2,3 or asign
-- ($t, $zip, $type) = ($1, $2, $3);
-- }
--

Do you have some figures to back up this claim? I get a marginal
difference, with the direct assignment being faster if the pattern
matches, and the delayed assignment being faster if the pattern doesn't
match. Considering that the difference is less than 1 microseconds,
I wouldn't base my decision which code to use based on speed.


Abigail
--
perl -wle\$_=\<\<EOT\;y/\\n/\ /\;print\; -eJust -eanother -ePerl -eHacker -eEOT
.