Here is a snippet of a script I am working on. It doesn't do what I
expect, which is simply to remove all of the occurrences of certain
characters from a string using the transliteration (tr///) operator.
However, it works perfectly when I put those characters into a
character class, change the "tr" to "s", and do a regular
expression-based substitution with the "/g" modifier.
(Like this: s/[''""$ ,]//g)
So I must be misusing the transliteration operator -- can someone
please explain why it doesn't work? I thought that this would replace
any incidence of the characters in the first string with the characters
in the second string -- in this case, removing them altogether.
Thank you,
Erik
PS: the quotes in the first string are duplicated b/c jEdit's syntax
highlighting gets messed up if I don't.
#!/usr/bin/perl -w
use strict;
unit_test();
# strip out the dollar signs and quotes from currency fields
sub clean_currency {
my $money = shift(@_);
$money =~ tr/''""$ ,//;
return $money;
}
# unit testing
sub unit_test {
# test clean_currency
my @currencies = ('$3,000', '$$4000',
"'\$2,,'", '"00300"');
my @transformed_currencies;
foreach my $currency (@currencies) {
push(@transformed_currencies,
clean_currency($currency));
}
print("clean_currency: @transformed_currencies\n");
}
__________________________________________________
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
http://faith.yahoo.com
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm