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:
String comparison help

 



skotagi
New User

Sep 8, 2010, 2:34 PM

Post #1 of 4 (2116 views)
String comparison help Can't Post

All,

I need to lookup for the keyword 'CPU' in the below event for string comparison. I have assigned the variable $SQL_wso_filters = ".*name=.*CPU.*";. When comparing ....if ($SQL_wso_filters =~ m/\d+@ARGV/ix) ) it's not matching, where @ARGV is thebelow event. I am assuming something is not working with $SQL_wso_filters = ".*name=.*CPU.*"; Any help is appreciated?




"%CAOPS_E : severiy=Error, principalName=chmgwds9sql01.corp.transunion.com, monitoringObjectName=name=Total CPU Utilization Percentage is too high, description=The threshold fr the Processor\% Processor Time\_Total performance counter has been exceeded.
he values that exceeded the threshold are: 99.688012695312494% CPU and a proces
or queue length of 17"


1arryb
User

Sep 8, 2010, 4:29 PM

Post #2 of 4 (2112 views)
Re: [skotagi] String comparison help [In reply to] Can't Post

Hi skotagi,

Probably $ARGV[0] contains the event, not @ARGV.

Also, You have confused the pattern with the search string in your code.

Finally, it's not a good idea to process @ARGV directly: Assign it to your own variable.

Try:

Code
my $str = $ARGV[0]; 
...
if ( $str =~ m/$SQL_wso_filters/ix ) {
...
}

Cheers,

Larry


skotagi
New User

Sep 8, 2010, 6:35 PM

Post #3 of 4 (2109 views)
Re: [1arryb] String comparison help [In reply to] Can't Post

Hi Larry,

Thanks for replying. Below is the code. $ARGV[0] contains only the NODEID. I think $no_of_args contains the event. I tried the below code but it won't work. I am wondering the statement my $SQL_wso_filters = ".*name=.*CPU.*"; is incorrect way to assign the pattern to search for.


$NODEID = "$ARGV[0]";
my $no_of_args = @ARGV;

my $SQL_hostname = "^ch.*sql.*com\$|^ch.*spo.*com\$|^ch.*vsql.*com\$";


my $SQL_wso_filters = ".*name=.*CPU.*";


if ( ($NODEID =~ m/$SQL_hostname/ix) && ($no_of_args !~ m/$SQL_wso_filters/ix) )

{

`logforward -f$NODEID -nchmgwesm9nsm02 -cred -t"SQL"`;

}

elsif ( ($NODEID =~ m/$SQL_hostname/ix) && ($no_of_args =~ m/$SQL_wso_filters/ix) )

{

`logforward -f$NODEID -nchmgwesm9nsm02 -cred -t"WSO SQL"`;

}

In Reply To


1arryb
User

Sep 9, 2010, 6:38 AM

Post #4 of 4 (2097 views)
Re: [skotagi] String comparison help [In reply to] Can't Post

Hi skotagi,

Like all Perl arrays, @ARGV will return the number of elements if
you call it in scalar context. Consider this little script:

Code
my $nArgs = @ARGV; 
print ("nArgs=$nArgs, ARGV=", join(', ', @ARGV), "\n");

Save that to a file called tmp.pl and run it with some arguments:

Code
# perl tmp.pl Huey Dooey Looey 
nArgs=3, ARGV=Huey, Dooey, Looey
#

So, we don't really know what the value of @ARGV is; except
that there appears to be more than one argument. Why don't
you add some instrumentation at the top of your program to
print it out?

Code
print "DEBUG: ARGV:\n"; 
for (my $i = 0; $i < scalar(@ARGV); $i++) {
print(" ARGV[$i] = \"$ARGV[$i]\"\n");
}

Once you understand what input your program is getting (I'm kind of getting that you aren't typing it yourself on a command line, right?), you will be in a better position to parse it.

Cheers,

Larry

 
 


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

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