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: Regular Expressions:
Can anyone help me ?

 



eeduest
New User

Sep 5, 2014, 3:40 PM

Post #1 of 4 (16810 views)
Can anyone help me ? Can't Post

Hi everyone;

I'm stuck with the following and i would like to know if someone of you can help me. I'm trying to develop a script, the purpose is to match different counters from a log file and store them in a hash, in order to do that i need the correct regular expression to match for the below counters and their respective values:

==============

HD verbose statistics

Retried reads: 0
Retried writes: 3
Corrected sectors: 0
Write verify failures: 0
Interrupt timeouts: 0
HD busy timeouts: 0
HD busy delays: 0
HD max busy delay: 0
HD status errors: 0
HD corrected by disk: 0
Error handling restarts: 0

so i'm doing the following:

if (/HD\sverbose\sstatistics/){
$step =1;
}
elsif(($step eq 1) && (/^(\S+\s+\S+)\s+(\S+)/)){
my $counter =$1;
my $statistic =$2;
if ($counter ~~ @list){
$hash{$node}{$counter}{statistic} = $statistic;
}
}

The above code is fetching for the counters (Retried reads: Retried writes: Corrected sectors: Interrupt timeouts: ) and storing them in this hash: $hash{$node}{$counter}{statistic} = $statistic; the list "list" includes the counters mentioned

My regular expression is only fetching for words included in @list that have only one "space" in each of them, now i need a better regular expression to fetch for all counters (including those who have 2 or more spaces) and store them in the same hash, can someone help me?

Thanks in advance
/Ed


Chris Charley
User

Sep 6, 2014, 8:46 AM

Post #2 of 4 (16781 views)
Re: [eeduest] Can anyone help me ? [In reply to] Can't Post

If there is a colon in your data, maybe the following would work out for you.


Code
/^([^:]+):\s+(\d+)$/


This captures non-colon up to the colon, matches the colon and space(s) and finally captures the statistic.


FishMonger
Veteran / Moderator

Sep 6, 2014, 9:30 AM

Post #3 of 4 (16777 views)
Re: [eeduest] Can anyone help me ? [In reply to] Can't Post

Why not simply do a split on colon space? IMO it's cleaner and easier to maintain.


Code
my ($counter, $statistic) = split /:\s+/;



eeduest
New User

Sep 8, 2014, 6:01 AM

Post #4 of 4 (16687 views)
Re: [Chris Charley] Can anyone help me ? [In reply to] Can't Post

Thanks! that worked out well.
BR/
Ed

 
 


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

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