Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Trouble opening and reading file within loop

by tangent (Parson)
on Sep 22, 2015 at 13:00 UTC ( [id://1142730]=note: print w/replies, xml ) Need Help??


in reply to Trouble opening and reading file within loop

@files only contains the names of the files, so you need to prepend the directory path. You can change this bit:
open my $fh, "<", $file or die "Can't open '$file': $!";
to...
open my $fh, "<", "Configs/$file" or die "Can't open '$file': $!";
Update:
In light of what GotToBTru says below, and although other ways have already been pointed out, you could add these lines:
foreach my $file (@files) { next if $file =~ m/^\./; # skip .. and . next unless -f "Configs/$file"; # test to see if a file open my $fh, "<", "Configs/$file" or die "Can't open '$file': $!";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-03-28 16:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found