Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Stumped with $_ being modified

by jdporter (Paladin)
on Jan 09, 2003 at 05:25 UTC ( [id://225444]=note: print w/replies, xml ) Need Help??


in reply to Stumped with $_ being modified

# 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://225444]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-03-28 12:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found