in reply to Re^3: push to an array lines matching a pattern, and the lines before and after the matching
in thread push to an array lines matching a pattern, and the lines before and after the matching

sorry, I updated only the first post with the correct timings
ack from the command line, takes 15 seconds
this code, simpler than your pseudo code, takes 10 seconds
use 5.014; use warnings; use Time::HiRes qw(usleep ualarm gettimeofday tv_interval); my @array; my $pattern = '\bsala|che|relazione|di|questo|coso|^qui\$'; open( my $filehandle, "<textMatchInAfile.txt" ); my $time = [gettimeofday]; while (<$filehandle>) { if ( $_ =~ /$pattern/ ) { push @array; } } say 'time while' . tv_interval($time);
  • Comment on Re^4: push to an array lines matching a pattern, and the lines before and after the matching
  • Download Code