I am not a Perl expert, but have a question about the join operator. Lets say I want to delete all multiline comments in a c/c++ source file. Also suppose my record separator is the default newline. This is how I would do it: read all the lines from the file into a list. The lists elements represent the lines in the source separated by \n. I then use join to combine all the lines into one big string. Then I use regex substitution to replace all /*.....*/ with blank. At least that is how I would do it. My main concern is whether it is sensible to use join in this way with respect to memory usage. Is join inherently inefficient? I have not seen many C source files > 10 MB; I might have to do something similar for larger XML files perhaps. Any better ideas to remove multi line comments from a c source?

In reply to joining lines efficiency? by perlperlperl

Title:
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, details, 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, summary, 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.