CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Perl pattern match to end of line

 



rdowd
New User

Jun 13, 2013, 6:46 AM

Post #1 of 3 (353 views)
Perl pattern match to end of line Can't Post

Hi All,

I'm trying to use Perl to read in file contents and grab some values (via pattern match) in the file.

My File contents is as below:

Total number of testcases executed: 100
Number of passing testcases: 20
Number of failing testcases: 80
..more file contents here not shown..

I've read the file into a variable and I want to get the value "20" out of the line:
"Number of passing testcases: 20"

I'm using the below:

if ($fileContents =~ m/Number of passing testcases*/s) {
print("Match\n");
print("LINE = [$&]\n");
} else {
print("No Match\n");
}

How to I grab the value of "20" on that line. As this number could be any number?

Any help would be great.
ps: I'm using Perl 5.10.1

Thanks - Ro


FishMonger
Veteran / Moderator

Jun 13, 2013, 7:44 AM

Post #2 of 3 (348 views)
Re: [rdowd] Perl pattern match to end of line [In reply to] Can't Post


Code
if ($fileContents =~ /Number of passing testcases executed:\s*(\d+)/) { 
print("Match\n");
print("LINE = [$1]\n");
}
else {
print("No Match\n");
}



rdowd
New User

Jun 13, 2013, 8:02 AM

Post #3 of 3 (346 views)
Re: [FishMonger] Perl pattern match to end of line [In reply to] Can't Post

Nice one - thanks!
Ro

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives