I'm writing some code to make a breadcrumb trail type thing and was wondering which of the following two methods would be faster.....
my $crumb = $DB->select( ['Full_Title'], 'Categories', { ID => $cid } )->fetchrow_hashref;
# Split the title at every /
my @row = split /\//, $crumb->{Full_Title};
# Loop though the categories and grab their ID for the hyperlink.
for (@row) {
my $id = $DB->select( ['ID'], 'Categories', { Title => $_ } )->fetchrow_hashref;
$output .= qq|<some link?catid=$id->{ID}">$_</a> > |;
}
-OR- (my favorite ).......
my $crumb = $DB->select( ['Full_Title'], 'Categories', { ID => $cid } )->fetchrow_hashref;
# Build the trail.
my $trail = join (qq{ $CFG->{DISPLAY}->{delimeter} }, map { my $name = $DB->select( ['ID'], 'Categories', { Title => $_ } )->fetchrow_hashref; qq|<a href="$GLOB->{script_url}?catid=$name->{ID}">$_</a>| } split /\//, $crumb->{Full_Title});
Thanks.
Code:
# Select the full category path for the breadcrumb trail. my $crumb = $DB->select( ['Full_Title'], 'Categories', { ID => $cid } )->fetchrow_hashref;
# Split the title at every /
my @row = split /\//, $crumb->{Full_Title};
# Loop though the categories and grab their ID for the hyperlink.
for (@row) {
my $id = $DB->select( ['ID'], 'Categories', { Title => $_ } )->fetchrow_hashref;
$output .= qq|<some link?catid=$id->{ID}">$_</a> > |;
}
-OR- (my favorite ).......
Code:
# Select the full category path for the breadcrumb trail. my $crumb = $DB->select( ['Full_Title'], 'Categories', { ID => $cid } )->fetchrow_hashref;
# Build the trail.
my $trail = join (qq{ $CFG->{DISPLAY}->{delimeter} }, map { my $name = $DB->select( ['ID'], 'Categories', { Title => $_ } )->fetchrow_hashref; qq|<a href="$GLOB->{script_url}?catid=$name->{ID}">$_</a>| } split /\//, $crumb->{Full_Title});
Thanks.