in reply to Detect Two Strings in File
Fiddle around with the DATA-section to check the various possibilities and combiinations.use Modern::Perl '2014'; my $first = qr/STRING/; my $second = qr/MAGIC/; my $corpus = join '', map { chomp; $_ } <DATA>; if ( $corpus =~ m/($first)(?!.*$first).*($second)(?!.*$first)/ ) { say "Success: $-[1] and $-[2]"; } else { say "Failure"; } __DATA__ First line second line here is the STRING empty text the STRING again! followed by the MAGIC word more emptiness Oh no! the first STRING again sadness did we look in vain? Yes, It's like MAGIC we are happy Ah, STRING and MAGIC success MAGIC and STRING failed
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: Detect Two Strings in File
by omegaweaponZ (Beadle) on Nov 07, 2014 at 13:29 UTC |