Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Wait a minute, I know that +< and seek can make things quite complex, and too many seeks may lower the performance, but we have to look at this case by case. If we can write a program by using seek and +<, yet it is very neat and no performance issue, then why not?
use Fcntl qw(SEEK_CUR SEEK_END); #import constant use strict; use warnings; use constant CLOSING_TAG => "</events>"; #deinfe the closing tag as co +nstant my $event1 = "<event time=\"time1\" type=\"type1\"><detail>detail1</de +tail></event>"; open(LOGFILE, "+<", "log.xml"); seek(LOGFILE, -length(CLOSING_TAG), SEEK_END); my $cur_char; #you may have newlines, blanks etc after the closing tag #that's why we do the following to make the program robust do { sysread(LOGFILE, $cur_char, 1); seek(LOGFILE, -2, SEEK_CUR) if ($cur_char ne "<"); } until ($cur_char eq "<"); seek(LOGFILE, -1, SEEK_CUR); print LOGFILE $event1 . "\n"; #you can do as many prints as you want before close #no more seek, we did it once and forever print LOGFILE CLOSING_TAG; close(LOGFILE);

In reply to Re: XML log files by pg
in thread XML log files by dingus

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (8)
    As of 2019-05-21 11:28 GMT
    Find Nodes?
      Voting Booth?
      Do you enjoy 3D movies?

      Results (132 votes). Check out past polls.

      • (Sep 10, 2018 at 22:53 UTC) Welcome new users!