Huh..
Thanks a ton. I never expected a program. :-)).

regards
-Ajey

On Sun, 16 Jan 2005, Dave Gray wrote:

On Sat, 15 Jan 2005 01:25:21 -0800 (PST), Ajey Kulkarni <[EMAIL PROTECTED]> wrote:
I'm trying to match a floating point in ada.
They are normal floating points with 2 extra things.(they can or can't
come)

1. an underscore is permitted between the digits and
2. An alternate numeric base may be specified surrounding the nonexponent
part of the number with pound signs, precided by a base in decimal.

Eg: 16#6.a7#e+2, 18.9,

Sounds suspiciously like homework, but that's a fun problem.

__CODE__
#!/usr/bin/perl
use strict;
use warnings;

my @numbers = (
 '16#6.f7#e+2',
 '18.9',
 '2#01013#',
 '16e+2',
);
my @valid   = (0 .. 9, 'a' .. 'z');

for my $num (@numbers) {
 my ($base, $n, $exp);
 if ($num =~ /^(\d+)\#([^\#]*?)\#(?:e\+(\d+))?$/x) {
   ($base, $n) = ($1, $2);
   $exp = defined $3 ? $3 : 1;
 } elsif ($num =~ /^(\d[\d._]*?)(?:e\+(\d+))?$/) {
   ($base, $n) = (10, $1);
   $exp = defined $2 ? $2 : 1;
 }
 next if not $n;
 my $invalid = '[^._'.join('',@valid[0..($base-1)]).']';
 warn "invalid base $base number [$n] detected! ($invalid)\n"
   if $n =~ /$invalid/;
 print "got base $base, num $n, exp $exp\n";
}
__END__

That should (more than) get you started!

HTH,
Dave

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to