Mark Reed skribis 2005-09-20 14:31 (-0400): > Not necessarily. Consider this common idiom (in pseudo-perl5):
Common, but widely regarded as bad style. The solution is templating and factoring in templates. But disregarding that, The trick is to not see it as "pre; midsection; post;" versus "midsection;", but as simply "foo; bar; baz;". for my $item (@menu) { if ($item->there) { printf( "<li>%s</li>\n", encode_entities($item->label), ); } else { printf( "<li><a href="%s">%s</a></li>\n", uri_escape($item->url), encode_entities($item->label), ); } } This has so little redundancy that it makes very little sense to want to avoid repeating that very short encode_entities($item->label). (I'd actually prefer something like: for my $item (@menu) { my $label = encode_entities $item->label; my $href = uri_escape $item->url; my $there = $item->there; print qq[<li>$label</li>\n] if $there; print qq[<li><a href="$href">$label</a></li>] if not $there; } instead.) Juerd -- http://convolution.nl/maak_juerd_blij.html http://convolution.nl/make_juerd_happy.html http://convolution.nl/gajigu_juerd_n.html