in reply to Extracting lines starting with a pattern from an array
use Modern::Perl qw/2015/; my @regex = <DATA>; chomp @regex; my $regex = join '|', @regex; $regex = qr/$regex/; open( my $FH, '<', 'data.txt' ) or die "Could not open file: $!"; while ( my $line = <$FH> ) { print "Matched $1 at $line" if $line =~ m/^($regex)/; } __DATA__ GSAD1234 GSAD2345 GSAD4567
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog: Imperial Deltronics
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Extracting lines starting with a pattern from an array
by Alessandro (Acolyte) on Dec 17, 2015 at 16:15 UTC | |
by u65 (Chaplain) on Dec 18, 2015 at 11:37 UTC | |
by hippo (Archbishop) on Dec 18, 2015 at 12:19 UTC |