in reply to Unable to find a pattern
There are a number of things you ought to tidy up in your code. First off, always use strictures (use strict; use warnings;).
Use the three parameter version of open.
Avoid slurping files (@file=<FILE>;).
Use a precompiled regex instead of interpolating a string into a regex.
Early exits and statement modifiers work very well to eliminate excessive indentation (see next unless $_ =~ $find; below).
Multiple ! marks are a sure sign of a demented mind (although that may not be a programming tip). :-)
Consider the following reworked example:
use strict; use warnings; my $license = 'Wibble'; open FILE, '<', $license || die ("Could not open the file\n"); my $find = qr'license @abc'; while (<FILE>) { next unless $_ =~ $find; print "Found!\n"; print "$_\n"; }
|
|---|