Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Insert lines into specific stanza line

by jonadab (Parson)
on Aug 13, 2010 at 19:17 UTC ( #854984=note: print w/replies, xml ) Need Help??


in reply to Insert lines into specific stanza line

It took me three or four minutes to figure out what your for loop does, and I still have no idea what it has to do with the stated problem. I think I would try a different approach altogether...

open INPUT, '<', 'inputfile'; open OUTPUT, '>', 'resultsfile'; local $/ = "</stanza>"; while (<INPUT>) { my $stanza = $_; if ($stanza =~ /<stanza/) { my ($dottedquad) = $stanza =~ /<stanza\s*(\d+[.]\d+[.]\d+[.]\d+)\s*>/; $stanza .= " sl3 yet another line\n"; # Make other changes to $stanza here as desired. print OUTPUT $stanza . $/; }}

Replies are listed 'Best First'.
Re^2: Insert lines into specific stanza line
by oko1 (Deacon) on Aug 13, 2010 at 19:34 UTC

    Unfortunately, your code is incorrect, and will produce the following output:

    <stanza 12.34.56.78> sl1 this is my line sl2 justanotherline </stanza> sl3 yet another line </stanza>

    Also, there's no newline at the last line of the above, so any subsequent additions will not be correctly formatted.


    --
    "Language shapes the way we think, and determines what we can think about."
    -- B. L. Whorf

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://854984]
help
Chatterbox?
[1nickt]: They assume that I want things I don;t and don;t provide things I do want. Looking for a 17" laptop with 4k (even 3K display) and full numeric-pad keyboard.
[1nickt]: They assume that if I want a 17" monitor I could not possibly want 4k screen
[1nickt]: They assume I do not need a DVD drive
[1nickt]: Heh, or they assume that if I want all that I am a "gamer" and I must want red backlighting for the keyboards and that I will pay $3500 ...
[stevieb]: what is your budget? HP 17" 4k display, DVD writer, full numeric keypad
[stevieb]: $1500 USD

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2017-03-26 18:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (315 votes). Check out past polls.