matching ??

T

Tim

data: s1 s2 s3 0.900 0.890 0.588
data2: s1 s2 s3 2.900F 1.890F 0.888
data3: s1 s2 s3 1.900F 6.890F 0.388F

My ReqX:
I would like to store the data in @name using the expression below:
@name = m/(\d+\.\d+)/g;
however, It does not ALWAYS work because for this case

data2: s1 s2 s3 2.900F 1.890F 0.888
$name[0] = 2.900 but I want $name[0] = 2.900F
$name[1] = 1.890 but I want $name[1] = 1.890F
$name[2] = 0.888

Please help.
 
A

Andreas Kahari

data: s1 s2 s3 0.900 0.890 0.588
data2: s1 s2 s3 2.900F 1.890F 0.888
data3: s1 s2 s3 1.900F 6.890F 0.388F

My ReqX:
I would like to store the data in @name using the expression below:
@name = m/(\d+\.\d+)/g;
[cut]

What about

@name = m/(\d+\.\d+F?)/g;

or maybe

@name = m/(\d+\.\d+\w?)/g;
 
J

J. Gleixner

Bernard said:
(e-mail address removed) (Tim) wrote in @posting.google.com:

data: s1 s2 s3 0.900 0.890 0.588
data2: s1 s2 s3 2.900F 1.890F 0.888
data3: s1 s2 s3 1.900F 6.890F 0.388F

My ReqX:
I would like to store the data in @name using the expression below:
@name = m/(\d+\.\d+)/g;
however, It does not ALWAYS work because for this case

data2: s1 s2 s3 2.900F 1.890F 0.888
$name[0] = 2.900 but I want $name[0] = 2.900F
$name[1] = 1.890 but I want $name[1] = 1.890F
$name[2] = 0.888

Please help.

Since it appears you want to capture the value in the columns 4-6, why
not use split?

$_ = '1 s2 s3 1.900F 6.890F 0.388F';
my (@name) = (split)[3,4,5];
print "@name\n";
1.900F 6.890F 0.388F
 
T

Tore Aursand

data: s1 s2 s3 0.900 0.890 0.588
data2: s1 s2 s3 2.900F 1.890F 0.888
data3: s1 s2 s3 1.900F 6.890F 0.388F

My ReqX:
I would like to store the data in @name using the expression below:
@name = m/(\d+\.\d+)/g;
however, It does not ALWAYS work because for this case

data2: s1 s2 s3 2.900F 1.890F 0.888
$name[0] = 2.900 but I want $name[0] = 2.900F
$name[1] = 1.890 but I want $name[1] = 1.890F
$name[2] = 0.888

Why bother using regular expression to do something this simple? split()
would do, wouldn't it?

my @data = ();
while ( <DATA> ) {
chomp;
my @tmp = split( /\s+/ );
push( @data, $tmp[4] );
push( @data, $tmp[5] );
push( @data, $tmp[6] );
}

No problem substituting the three push() calls with only one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top