Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: regex: finding something followed explicitly by a dot

by ayrnieu (Beadle)
on Feb 12, 2006 at 00:33 UTC ( [id://529614]=note: print w/replies, xml ) Need Help??


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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://529614]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-24 19:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found