I could use a loop, but thought someone might have a better way.
Impossible. You can't visit each string in the array without looping over the array. Same goes for each character of those strings. The type of loop may vary, that's all.
Here are some ways:
my @CLEANED = map { ( my $s = $_ ) =~ tr/\000//d; $s } @EMPLOYEES;
# Requires Perl 5.14 my @CLEANED = map { s/\000//r } @EMPLOYEES;
map { tr/\000//d } my @CLEANED = @EMPLOYEES;
my @CLEANED = @EMPLOYEES; tr/\000//d for @CLEANED;
use List::MoreUtils qw( apply ); my @CLEANED = apply { tr/\000//d } @EMPLOYEES;
use Algorithm::Loops qw( Filter ); my @CLEANED = Filter { tr/\000//d } @EMPLOYEES;
I'd avoid the following because it "cleans" both @EMPLOYEES and @CLEANED:
my @CLEANED = map { tr/\000//d; $_ } @EMPLOYEES; # XXX
Update: I definitely avoid the snippet I originally posted as "I'd avoid", since it cleaned @EMPLOYEES and produced junk in @CLEANED. Fixed.
In reply to Re: Remove nulls, or other Chars
by ikegami
in thread Remove nulls, or other Chars
by Saved
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |