good $localtime fellow monks,

I am tearing my hair out over a small oddity. Why will this work:

perl -nle "my (@c) = /\:(\w+)\:/g; print join '.', @c" input> out:caputure1:out:capture2:out output> caputure1.capture2

But this behaves so differently

perl -nle "my (@c) = s/\:(\w+)\:/X/g; print join '.', @c" input> out:caputure1:out:capture2:out output> 2

I am trying to extract comments from a file I have in a buffer read in with local $/;. The comments are marked by a ; and continue to the end of the line. For various reasons I want the file as a sinlge line and want to extract the comments. The comments will be added back in later so I substiture them for a marker. I realise I could break the file into lines and put it back together again later but I would love to be able to do it in one line

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

In reply to s///g and capturing all matches by Random_Walk

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.