# etc #### sub read_template { my ($templfile, $hashref) = @_; my ($line, $dest, $stuff); my $fh = new FileHandle("<$templfile"); # This looks like a C idiom. # $dest is initially set to point to $stuff (which is # undef). # # If a template start is found, the hash key is set with # the template name, and # $dest is re-pointed at the value corresponding to this # hash key. # # Subsequent lines are appended to $dest (and hence to # the hash value), # until a closing tag is found, at which point $dest is # re-set to $stuff again. # # The hash is a reference, so we are also modifying the # caller at the same time. Nothing is explicitly # returned. # $dest = \$stuff; while ($line = <$fh>) { if ($line =~ /^\s*<\s*TEMPLATE\s+NAME="(.*)"\s*>/i) { $hashref->{$1} = ''; $dest = \$hashref->{$1}; } elsif ($line =~ /^\s*<\s*\/\s*TEMPLATE\s*>/i) { $dest = \$stuff; } else { ${ $dest } .= $line; } } $fh->close; }