TIMTOWTDI/Tangential observations (See the on-target discussions of interpolation by toolic, AnomalousMonk and Anonymonk, above):

Your asterisk, vertical_bar and questionmark are special chars in a regex; specifically, the "*" and "?" are quantifiers. So, since the asterisk appears first in your array, you're trying to feed the regex engine a quantifier without an antecedent; i.e., without anything to match.

So, another way around this would be to escape those characters that have special meaning in a regex; viz:

#!/usr/bin/perl use strict; use warnings; # 846423 my $id='TEST TEST foo|bar*test'; my @testdata = split(/ /, $id); print "Pre-regex: $id\n"; my @filename_filter=('\*', '\|', '<', '>', '\?', '/'); # $id =~ s/[@filename_filter]//g; for my $filename_filter(@filename_filter) { $id =~ s/$filename_filter//g; } print "post-regex: $id\n\n"; for my $testdata(@testdata) { for (@filename_filter) { my $regex = qr($_); $testdata =~ s/$regex//; } print "split&regex: $testdata\n"; }
prints:
Pre-regex: TEST TEST foo|bar*test post-regex: TEST TEST foobartest split&regex: TEST split&regex: TEST split&regex: foobartest

This appears to satisfy your spec without changing $", the $LIST_SEPARATOR. It IS the long way around, and not merely because my code goes out of it's way to be explicit, but perhaps addresses a closely related issue.

Update: corrected citation to refer to all the preceding, correct discussions of interpolation


In reply to Re: How do I stop this from removing spaces? by ww
in thread How do I stop this from removing spaces? by neXussT

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.