Thanks for your earlier help with the find module and the file tests.

I am getting a list of text files using the find module and the file tests.

Im saving the paths to these files into an array, I then want to open them for writing using a file handle.

So I use a foreach statement to loop through the array and open a file handle for each file, i then use a while loop on the filehandle to read each line at a time. But it doesnt work. I think the file can be accessed because i get no error messages. What is wrong.

Japhy has replied saying the code works on his machine. I'm using osx and perl, could that be a problem.

No the files only contained no data. doh.

#!/usr/local/bin/perl -w # print warnings use strict; # install all three strictures # program to open files in a directory and change directory paths fro +m oldpath to $newpath # use stat function to mke file handles available $|++; # force auto flush of output buffer use File::Find; use Cwd; use File::Path; my @ListofFiles; my $Start_dir = shift or die "usage: $0 <start_dir>\n"; #define string directory as <ST +DIN> # scan recursivley from the start directory unless ( -d $Start_dir ) { die "Start directory .'$Start_dir' . is not a directory.\n"; } sub wanted { my $fileopened = $File::Find::name; my $fileout = "$fileopened.NEW2"; if ( -e $fileopened ) { #print "Found $File::Find::name\n"; } if ( -T $fileopened ) { #print "$File::Find::name is a DATA file\n"; push( @ListofFiles, $fileopened ); } else { #print "Didn't OPEN $File::Find::name\n"; } } sub searchfiles () { my $a; #print "$fileout\n"; foreach $a (@ListofFiles) { print "$a\n"; ( open FILEOPENED, "$a" ) or die "couldn't open the file $!" +; while (<FILEOPENED>) { print "file is opened for reading"; } close(FILEOPENED); } } find( { wanted => \&wanted, no_chdir => 1 }, $Start_dir ); searchfiles();

In reply to using filehandle to open files listed in array by richill

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.