I'm looking for some recommendations/best practice/elegant solutions for the following (This code already produces the right results).
I was surprised by the fact that Method#2 (My original code) is SLOWER than Method#1.
use strict; use warnings; my $x= <<"__X__" x 4; # Increase multiplier for benchmarking A data for A B data for b C data for c __X__ # Method #1 - works but I don't like using $1,$2 - would rather use na +mes while($x=~/(^A|^B)(.+)$/mg){ print "$1 method1 $2\n" } # Method #2 - open my $f,"<",\$x or die $!; while(<$f>){ my ($name,$data) = m/(^A|^B)(.+)$/ or next; print "$name method2 $data\n" } close $f; # Method #3 (infinite loop) #while(my ($name,$data)=$x=~/(^A|^B)(.+)$/mg){ # print "$name method3 $data\n" #}
"These opinions are my own, though for a small fee they be yours too."
In reply to Extracting /regex/mg in a while loop by NetWallah
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |