Hi,

I am trying to match phone numbers, and want only having format xxx-xxxx.

Here is what i have written so far :

sub OfficePhoneNumber
{
my @numbers = @_;
my $number;
my @results;
foreach $number (@numbers)
{
if ($number =~ m/(^\d{3}-\d{4}$)/)
{
push @results, $number;
}
}

return @results;
} 

&OfficePhoneNumber "554-321,+1 302-342-2323";

Please suggest on this.

Thanks, John

Recommended Answers

All 3 Replies

The problem is syntax of the passing values through the subroutine. you will be modify this line.

&OfficePhoneNumber ("554-3211","+1 302-342-2323");

Thanks for the response.

I might have input like this :

&OfficePhoneNumber ("554-3211","444-4565");

However, i want only one value either first one or the second but not both. As the value can be found at either places.

At time we might get this also,

&OfficePhoneNumber ("","444-4565");

John

Thanks it was simple. i am able to do that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.