Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pattern matching problem

Status
Not open for further replies.

jj0914

Programmer
Joined
Aug 4, 2006
Messages
33
Location
CA
i am trying to do a pattern match in one of my perl script, but I couldn't figure out what expression i can use, here is the line i wanna match:

ds[traffic_out].value = 8.4164256667e+04

can anyone give me a help on this?

thanks
 
ds[traffic_out].value = 8.4164256667e+04

/^\w*\d$/g with assumptions that:
Always starts with aplhabets and ends with number.
Is not case sensitive.
This is a greedy match so it will match the longest pattern.
 
ds[traffic_out].value = 8.4164256667e+04

/^\w*\d$/g with assumptions that:
Always starts with alphabets and ends with number.
Is not case sensitive.
This is a greedy match so it will match the longest pattern.
 
you did not say what you are trying to match so there is little point in posting code. Please explain exactly what you are trying to match in the line you posted.
 
i am running "rrdtool info" in my script, and i am trying to match one line from the result which I posted "ds[traffic_out].value = 8.4164256667e+04".

sorry about not clear, bad at express what I need : )
 
here is how I match:

"if($_ =~ /\[$ds\]\.value = ^(.*\d+))"

but I can't match the exponential part (the exponential part will be assigned to $1 once it is matched)
 
Code:
$str = "ds[traffic_out].value = 8.4164256667e+04" ;
if ( $str =~ /^\w+?\[\w+?\].value\s+=\s+(\w+?.\w+?\+.\w+)/ ) {
        print $1 ;
}

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
spookle, thank you for your help, it works, now i have another question. Do you guys know how to convert scientific notation into integer, for example, if the "$1 = 8.12456e+05" I wanna convert $1 into a integer like 812456.
 
Here's a relatively easy way:
Code:
use Math::BigFloat;
my $x = Math::BigFloat->new('8.12456e+05');
print $x->bstr();
 
Thanks rharsh,
it works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top