Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Dear Monks,

I'm looking for advice on how to complete what I'm finding to be a difficult task. What I'm dealing with are two files, (1) tagged ascii file (2) style sheet. Both files are generated from a proprietary typesetting system.

I want to be able to loop through the tagged ascii file and when I match a tag, pass it a subroutine and then replace it with the attributes for that particular tag from the style sheet. How can this be accomplished? Below is a small sample of the script I'm working with.

Thanks,
young_david

use strict; sub tagheader { my $header; open(STYLESHEET,'stylesheet.txt'); my $tag = shift; ########################################################### # "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 # while (<STYLESHEET>) { if (/^HEADER (\d+):/) { $header = $1; } if (/^nm : ($tag)/) { return \$header; } } close(STYLESHEET); } my $body; my $tag; open(FILE,'taggedfile.txt'); open(OUT,">$ARGV[0]"); while(<FILE>) { if (/^\{(\w+)\}/) { $tag = $1; $body = tagheader($tag); # Right here, $_ contains "nm : $tag" from the tagheader() # I see that $_ has been modified by tagheader() # This is my problem and I'm stumped :( s/\{($tag)\}/\{$1:$body\}/; # I want to search and replace the ($tag) with $1:$body # $body will contain a number that is assigned to the $tag # in the style sheet. } print OUT $_; } close(FILE); close(OUT); __DATA__ FILE { type : if } FILEHDR { File_Comment : "" } HEADER 1: { _std_comment : "" nm : TAG post : "" ppriority : 1st pmaxwhite : 0 } BODY 1:1 { endval : page priority : 1st ffamily : 2 fvariant : 3 fheight : 10q fwidth : same maxwhite : 0 prelead : no ldasc : normal lindent : 0 pgindent : 0 lnmeas : full ldextra : 2q lddesc : normal qdtbl : l hjtbl : 4 pgsplit : no lpabove : 0 lpbelow : 0 laabove : 0 labelow : 0 language : 1 xpath : "" capmode : no kernnum : 1 spotcolor : normal psrnum : 1 ipcrnum : active pair_kern : yes endstring : "" pre : "" repeat : repeat pgrful : none httbl : none pattern : none comment1 : "" }

Edit by tye to add READMORE


In reply to Stumped with $_ being modified by young_david

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 02:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found