Hi ozboomer, Try this,
use strict; use warnings; my ($int) = (split "!(?:INT=)?", "SLOT3=4,4,2!INT=115!VC=4!CS=270!PK=/ +")[1]; print "Method 1 :\t\$int: $int\n"; my ($int1) = ("SLOT3=4,4,2!INT=115!VC=4!CS=270!PK=/")=~ m/\!INT=([^\!] ++)/; print "Method 2 :\t\$int: $int1\n";
Comparsion of above methods.
use strict; use warnings; use Benchmark 'cmpthese'; cmpthese(-1, { method1 => 'my ($int) = (split "!(?:INT=)?", "SLOT3=4,4,2!INT=11 +5!VC=4!CS=270!PK=/")[1]', method2 => 'my ($int) = ("SLOT3=4,4,2!INT=115!VC=4!CS=270!PK=/") +=~ m/\!INT=([^\!]+)/', }); __END__ Rate method1 method2 method1 133487/s -- -64% method2 366033/s 174% --
Regards,
Velusamy R.
In reply to Re: Simple RegEx Substring Extraction from a Delimited Text Record
by Samy_rio
in thread Simple RegEx Substring Extraction from a Delimited Text Record
by ozboomer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |