Don't apologise for asking questions to find out about stuff you don't know! After all, that is exactly why you are visiting.

$_ is Perl's default variable. It is used as an alias to the current item for things like grep and map. It is also used in the same way when you use for as a statement modifier such as in $_ = wrapLine($_) for $module_cmd, $cfgmaker_cmd;. I used that trick by the way to save writing out:

$_ = wrapLine($module_cmd); $_ = wrapLine($cfgmaker_cmd);

and of course to expose you to some interesting Perl.

$line =~ m~(.{1,$kMaxLine})(?:\s|(?<![-.\w=/]))~g is a regular expression match. m is the match operator and uses the following non-whitespace character as the quote character for the regular expression string. In this case it's using ~ which I chose to avoid having to quote the / used in the match string. The g on the end is the "global match" flag - match as many times as you can. There is a lot more in that regular expression and I strongly encourage you to read perlretut and perlre to at least get an overview of whet regexes do and look like. You can simplify the regex line to:

return join "\n## ", $line =~ m~(.{1,$kMaxLine})~g;

to have it break the line into fixed size pieces without regard to white space or punctuation. You would find it instructive however to read the documentation for regexen engough to be able to figure out how the original regex works. ;)

True laziness is hard work

In reply to Re^3: Printing Fixed Width Strings and Spliting String into Multiple Lines by GrandFather
in thread Printing Fixed Width Strings and Spliting String into Multiple Lines by mmartin

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.