Pattern Search and Extraction of Floating Point number to csv file

R

Ram Laxman

Hi all,
Iam new to perl programming. I have written a program which
read a text file and import some values to the csv file searching some
tags(keyword) in the text file.

Below is the format of text file:

No of transactions = 10
Data exchanged with device = 0.5 bytes
Data sent to device = 0.04 KBytes

while( $key = <TEXTFILE> ) {
# check if it matches the tag
if ( $key =~ /$tag/i ) {
@arr_field = split( /$tag/i, $key );
foreach $afield( @arr_field ) {

if( $afield =~ /(\d+)/ ) {
$field = $1; # extract the numerical field
}

}
print CSV "$field\,"; # writes the numerical field to the
result file
last;

The statement below extracts the numerical field.
if( $afield =~ /(\d+)/

I don't know how to extract the floating point numbers.(For example
Data exchanged with device = 0.5 bytes) without truncation and
want to save the same value in my csv file.

Could anybody help me in this regard?

Regards
Ram Laxman
 
B

Brad Baxter

The statement below extracts the numerical field.
if( $afield =~ /(\d+)/

I don't know how to extract the floating point numbers.(For example
Data exchanged with device = 0.5 bytes) without truncation and
want to save the same value in my csv file.

Could anybody help me in this regard?

Perhaps one of the regex in:

perldoc -q 'whether a scalar is a number'

Regards,

Brad
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top