# Right here, $_ contains "nm : $tag" from the tagheader()
# I see that $_ has been modified by tagheader()
# This is my problem and I'm stumped :(
O.k., that's simple enough to fix:
Add a
local $_;
near the top of the body of
tagheader.
One thing I would do differently is load the contents
of the stylesheet file into an in-memory structure,
rather than re-read the file every time you need to
look up a tag.
Perhaps something like this:
{
my %tags;
# here's where we load the %tags:
open STYLESHEET, '< stylesheet.txt'
or die "Error opening stylesheet.txt: $!";
###########################################################
# "HEADER" appears before "nm" in the style sheet
# Find each "HEADER" in the file and assign $1 to $header
# If we find the $tag we're looking for return $header
#
local $_;
my $header;
while (<STYLESHEET>) {
if ( /^HEADER (\d+):/ ) {
$header = $1;
}
elsif ( /^nm : (\w+)/ ) {
$tags{$1} = $header;
}
}
close STYLESHEET;
# and here's the function we call to look up a tag:
sub tagheader {
my $tag = shift;
$tags{$tag}
}
}
PS: ++ to you for
using strict.
jdporter
The 6th Rule of Perl Club is -- There is no Rule #6.