Dear fellow monks,

I have a problem with qw, one of my favorite little perl tools.

Like all our good friends, the better you know them, the more little things that get on your nerves and the more you want to change them for the better!

Other monks have meditated on qw before , here is a replacement for it! :)

I want to have it ignore everything after a # sign on a line, i have a big ol' qw and want to comment one element out. What a pain!

Also it would be nice to explicitly create an undef, newline or \r element and not have it as a string.

Maybe it would look like this :

{ my %translate =( '\n'=>"\n", '\r'=>"\r", '\t'=>"\t" ); my $regex=join "|", map { quotemeta $_ } keys %translate; sub myqw { local $_ = shift; s/\#.+//g; # bye bye comments return map { if ($_ eq '\undef') { undef; # undef element in the array } else { s/($regex)/$translate{$1}/ge; # safer than eval $_; } } split " "; } } # test it print join "|", myqw (q[ this is a set of words # and they are commented as well a b b\t\te # b tab tab e c # d # remove d because we wont need it e\ne # e newline e g \undef h ]); __END__ this|is|a|set|of|words|a|b|b e|c|e e|g||h
thanks to demerphq in advance for the review (and lots of tips) on the post!

Edit: chipmunk 2001-11-09


In reply to qw comments by mdupont

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.