Perl, Assign to variable from regex match -



Perl, Assign to variable from regex match -

i relatively new perl , there illustration snippet of code in check_ilo2_health.pl in there piece of syntax not understand how or why works. code snippet parsing ssl client data, in case xml, line line.

if ( $line =~ m/message='/) { ($msg) = ( $line =~ m/message='(.*)'/); #<---- here if ( $msg !~ m/no error/ ) { if ( $msg =~ m/syntax error/ ) { #...etc

an illustration of xml in question:

<response status="0x0000" message='no error' />

so in case if statement takes message line of xml sample. understand my ($msg) treats variable sort of list , understand how regular expressions match; however, not understand syntax such $msg assigned no error. perl seems playing around parenthesis syntax , such work. while works know how works. assistance appreciated.

see perlretut, extracting-matches:

... in scalar context, $time =~ /(\d\d):(\d\d):(\d\d)/ returns true or false value. in list context, however, returns list of matched values ($1,$2,$3)

so, in

($msg) = ( $line =~ m/message='(.*)'/);

( $line =~ m/message='(.*)'/) returns list of matches capturing groups. have 1 capturing group, content of stored in ($msg).

regex perl syntax variable-assignment parentheses

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -