Original Post
I'm a noob to perl and I can't for the life of me figure out why my first code sample is faster than the second (by about 10%). I'd appreciate any feedback as to why this is. The second sample is easier (for me) to understand, but I would like to know why the first is faster. Faster:
while (my $line = <LOG>)
{
if( $line =~ /^(\d+)\t([^\t]+)\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d(?:\t(\d+)\t(.*)?)?/ )
{
if( defined($3) )
{
my $user = $1;
my $search = $2;
my $rank = $3;
my $site = $4;
if( $site =~ /$word/)
{
$userIDs{$user} = "$search : $site";
}
}
}
}
Slower:
while (my $line = <LOG>)
{
($user, $search, $date, $rank, $link) = split("\t", $line);
if( $rank =~ /./ )
{
if($link =~ /$word/)
{
chomp($link);
$userIDs{$user} = "$search : $link";
}
}
}