[ic] perl to strip hyphens etc?

Ed Waldspurger ewald at certifichecks.com
Tue Jun 22 11:20:22 EDT 2004


DB <mailto:DB at M-and-D.com> wrote:
> Ok I tried  the following but it seems to have no effect. I'm trying
> to remove hyphens from a phone number before I write it to a file.
> 
> #clean up phone numbers
> $phone_day=$array->{phone_day};
> $phone_day=~ s/[\-]+/ /g;
> print OUTFILE "$array->{phone_day}|";
> 
> Why does this not work? Any ideas?
> 
> DB

The variable you are printing is the original, not the one you changed. Try
printing $phone_day to OUTFILE instead of $array->{'phone_day'}

	my $array = {phone_day => '555-1212'}; 

	#clean up phone numbers
	my $phone_day = $array->{'phone_day'};
	$phone_day =~ s/[\-]+/ /g;
	print "Original Number: $array->{'phone_day'}\n";
	print "Filtered Number: $phone_day\n";

The code above should give you the following output.

Original Number: 555-1212
Filtered Number: 555 1212

Ed W.


More information about the interchange-users mailing list