Re: Might be OT - File::Find not reading tt files

Marco Palma <marcoapalma-/[email protected]> Mon, 21 May 2012 13:44:22 -0700 (PDT)
Newsgroups gmane.comp.lang.perl.modules.template-toolkit
Message-ID <[email protected]>
For reading in files I'd also recommend File::Slurp, which despite it's name can also write to files:

I'm fond of the way it simplifies the typical Perl idiom to a one liner:
my $text = read_file( 'filename' ) ;or if you want an array of lines:

my @lines = read_file( 'filename' ) ;

>________________________________
> From: Ronald J Kimball <[email protected]>
>To: Summer <crazysummer2004-/[email protected]> 
>Cc: [email protected] 
>Sent: Monday, May 21, 2012 12:14 PM
>Subject: Re: [Templates] Might be OT - File::Find not reading tt files
> 
>
>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
>
>
>

_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates