In addition to roboticus's comments, I'm a little surprised that you get the literal $line in your output. The $line inside the double quotes of each print statement should have interpolated just as the $| did in the second line. Unless, of course, you did something like $line = '$line'; in your code somewhere.

Your comments detailing what the lines do are inaccurate, for instance, /^\s+|#/ will match one or more spaces anchored to the beginning of the string or a hash anywhere. Is that what you meant? I expect you know this but note that if you are trying to match literal dollar and pipe symbols, they are regular expression metacharacters and should be escaped. Also, if you are trying to match a forward slash it can be more readable to choose a different regex delimiter. Putting all this together:

print '$line =~ s{^\s+#}{}; #trim leading spaces and comment hash', "\ +n"; print '$line =~ s{\s+/$}{}; #trim trailing spaces and forward slash', +"\n";

I hope I have guessed your intention correctly and that this is helpful.

Cheers,

JohnGG


In reply to Re: Code generation. Printing out regular expressions by johngg
in thread Code generation. Printing out regular expressions by Anonymous Monk

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.