Re: Might be OT - File::Find not reading tt files
Ronald J Kimball <rkimball-jkI2qz8QNLsmlAP/[email protected]> Mon, 21 May 2012 15:14:18 -0400
| Newsgroups | gmane.comp.lang.perl.modules.template-toolkit |
|---|---|
| Message-ID | <CAEnkCGQbCcbcVBZgPMyDnusZKx8j4SAXQ0pECpM2USGDEm1SfQ@mail.gmail.com> |
On Mon, May 21, 2012 at 2:49 PM, Summer <crazysummer2004-/[email protected]> wrote: > > I am using TT for all my pages and I am trying to create a simple shell > script that will scan all the tt files for a query match that I pass in. > > I am using the module File::Find > > The directories/files are traversed via the package but when I try to > print out the actual contents of the <FILE> it is empty. I am thinking that > the [% etc.. are somehow preventing reading in off all the data in the file. > > Here is a snippet I have: > print "Your Results are as Follows:\n"; > find( sub > { > return if ($_ =~ /^\./); > return unless ($_ =~ /\.tt$/i); > stat $File::Find::name; > return if -d; > return unless -r; > open(FILE, "< $File::Find::name") or return; > print "$File::Find::name\n"; > my $string = <FILE>; > close (FILE); > #print "$string\n"; > return unless ($string =~ /$pagepos/i); > print "Found Match: $File::Find::name\n"; > > The presence of [% in the file definitely has no affect on the ability of perl to read the contents of the file. <> in scalar context reads a single record from the filehandle; would that explain the behavior you are seeing? An easy way to read the entire file is to set $/ (the input record separator) to undef. For example: sub { ... local $/; my $string = <FILE>; ... } By the way, if you'd be interested in a pre-existing solution, check out ack, which has command-line options to specify which types of files to search, based on suffix. http://search.cpan.org/perldoc?ack Ronald _______________________________________________ templates mailing list [email protected] http://mail.template-toolkit.org/mailman/listinfo/templates