MikasaAckerman MikasaAckerman - 2 months ago 17
Perl Question

What is meant by the following regex?

I am working on kernel module and the module outputs a hex code which is being read by a perl script using regex.

I am not able to make sense out of it:

while (<>) {
s/^([a-fA-F0-9]+)(\.)([a-fA-F0-9]+)(\s+.*)/sprintf("%s%s%s%s", &$converter(hex($1)), $2, hex($3), $4)/oe;
} continue {
print;
}


We are trying to read hex code to time in nano second.

Answer
s/^([a-fA-F0-9]+)(\.)([a-fA-F0-9]+)(\s+.*)/sprintf("%s%s%s%s",  &$converter(hex($1)), $2, hex($3), $4)/oe;

There are 4 capturing groups, each is covered by brackets ():

$1 -> ([a-fA-F0-9]+)

$2 -> (\.)

$3 -> ([a-fA-F0-9]+)

$4 -> (\s+.*)

Details here