in reply to regex: finding something followed explicitly by a dot

Other people have already found your bug. I'd like show you how I'd think to write your program.
#! /usr/bin/env perl use strict; use warnings; BEGIN { die "usage: $0 <file> <word>" unless @ARGV==2 } sub file_has_word { my ($fn, $w) = @_; open my $f, $fn or die "$fn: $!"; local $/ = undef; # but why do you want this? return unless <$f> =~ /\Q$w/; 1 } print "found it!\n" if file_has_word(@ARGV);
Or possibly: grep 'LEAD_TYPE\.' SearchSet.java

Replies are listed 'Best First'.
Re^2: regex: finding something followed explicitly by a dot
by shenme (Priest) on Feb 12, 2006 at 15:29 UTC
    Why do you have your argument-checking 'die' inside a BEGIN block? The line would work as well without being enclosed in a BEGIN block (once a ';' was added at the end)
      Habit: sometimes I'd like to avoid other BEGIN or module processing. As near-cargo-cult code goes, is it very bad?