in reply to How do I stop this from removing spaces?
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:
prints:#!/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®ex: $testdata\n"; }
Pre-regex: TEST TEST foo|bar*test post-regex: TEST TEST foobartest split®ex: TEST split®ex: TEST split®ex: 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
|
---|