in reply to key value pair or simply a regexp

You're making this more difficult for us because you don't really specify the output you're specifically seeking.

Your code seems to indicate that you're looking for the associated value for the "msgagt" key (which has the value "ESM_WMB_AIX" in the data you provide). Is this correct?

My assumption is that this is what you're looking for. Given that,

my $data = qq(msgagt=ESM_WMB_AIX,sec_id=Sec_id,severity=Low,node=test, +msgnode=qwmbap01.xxxxxxxxxxxxx.net,utc=2007-04-26 18:01:59.472+00:00, +om=UID=3a7affd6-f420-11db-80b1-000000000000,AlertCode=AEM001,AlertTyp +e=AEM-default,AppName=AEM-CommonService2,Message=5004:An error has be +en reported by the BIPXML4C component.:XML); my ($msgagt) = $data =~ /msgagt=([^,]+)/; print $msgagt, "\n";

Am I missing any other specs for this problem?


Where do you want *them* to go today?

Replies are listed 'Best First'.
Re^2: key value pair or simply a regexp
by mikejones (Scribe) on May 18, 2007 at 20:43 UTC
    No you are not missing anything, and thank you b/c your regexp worked. I asked what I needed in the beginning which was everything between the = and , But if a new string is entered in the front, middle or end such as node1=xxxx, thats why I started out using key/value pairs. thx agn :)
      Was able to get it working! Yea! Thanks to thezip for pointing me in the right direction after a little mod, it works.
      #!/usr/bin/perl use strict; use warnings; my $out = qq(/home/smith/out); open (my $file, "+<", $out) or die $!; local $/ = ','; while (<$file>) { s/^\s+|\s+$//g; my ($msgagt) = $_ =~ /\w+=([^,]+)/; print $msgagt, "\n"; }

        That's fine, but you should understand the following idiom, because it's much more general and is applicable in this case too.

        $_ = <<EOF; msgagt=ESM_WMB_AIX,sec_id=Sec_id,severity=Low,node=test,msgnode=qwmbap +01.xxxxxxxxxxxxx.net,utc=2007-04-26 18:01:59.472+00:00,om=UID=3a7affd +6-f420-11db-80b1-000000000000,AlertCode=AEM001,AlertType=AEM-default, +AppName=AEM-CommonService2,Message=5004:An error has been reported by + the BIPXML4C component.:XML EOF my %hash = map { split /=/, $_, 2 } split /,/; print $hash{'msgagt'}, "\n";

        With this, you've loaded the entire string into a hash. You can then access the "variable" you want, e.g. msgagt, by simply looking it up in the hash.