On Mon, 09 May 2005 21:34:08 +0800, Aditi Gupta <[EMAIL PROTECTED]> wrote:

Can we use substr function for a string like:
$file = atom 12 N  VAL  A  1  12.435  13.66 34.6  32.1 32   a N
can the decimal numbers be extracted using
$x= substr($file, offset, length)
(the exact field lenghts of each field are known).


If you want only the decimal number_s_ looks like what you need
is a list.

__BEGIN__
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
my $file = 'atom 12 N  VAL  A  1  12.435  13.66 34.6  32.1 32   a N';

my @list = split(/\s+/,$file);
my @y = grep { $_ if ($_ =~ /\d+/)} @list;
print Dumper [EMAIL PROTECTED];

__END__

Gives:

$VAR1 = [
          '12',
          '1',
          '12.435',
          '13.66',
          '34.6',
          '32.1',
          '32'
        ];


Hope that's what yo wanted.


-- Regards, Edward WIJAYA SINGAPORE

--
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