Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As others have pointed out, if the end goal is only to remove lines starting with <code>//#</code>, for performance reasons you are probably better off using <code>grep</code> or <code>sed</code>:</p> <pre><code>grep -v '^\/\/#' filename.txt &gt; filename.stripped.txt sed '/^\/\/#/d' filename.txt &gt; filename.stripped.txt </code></pre> <p>or</p> <pre><code>sed -i '/^\/\/#/d' filename.txt </code></pre> <p>if you prefer in-place editing.</p> <p>Note that in perl your regex would be</p> <pre><code>m{^//#} </code></pre> <p>which matches two slashes followed by a # at the start of the string.</p> <p>Note that you avoid "backslashitis" by using the match operator <code>m{pattern}</code> instead of the more familiar <code>/pattern/</code>. Train yourself on this syntax early since it's a simple way to avoid excessive escaping. You could write <code>m{^//#}</code> just as effectively as <code>m%^//#%</code> or <code>m#^//\##</code>, depending on what you want to match. Strive for clarity - regular expressions are hard enough to decipher without a prickly forest of avoidable backslashes killing readability. Seriously, <code>m/^\/\/#/</code> looks like an alligator with a chipped tooth and a filling or a tiny ASCII painting of the Alps.</p> <p>One problem that might come up in your script is if the entire file is slurped up into a string, newlines and all. To defend against that case, use the /m (multiline) modifier on the regex:</p> <pre><code>m{^//#}m </code></pre> <p>This allows ^ to match at the beginning of the string <em>and</em> after a newline. You would think there was a way to strip or match the lines matching <code>m{^//#.*$}</code> using the regex modifiers <code>/g</code>, <code>/m</code>, and <code>/s</code> in the case where you've slurped the file into a string but you don't want to make a copy of it (begging the question of why it was slurped into a string in the first place.) It <em>should</em> be possible, but it's late and I'm not seeing the answer. However, one 'simple' way of doing it is:</p> <pre><code>my $cooked = join qq{\n}, (grep { ! m{^//} } (split m{\n}, $raw)); </code></pre> <p>even though that creates a copy instead of an in-place edit on the original string <code>$raw</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload