Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: Open a folder

by Lotus1 (Vicar)
on Jan 08, 2013 at 14:39 UTC ( [id://1012241]=note: print w/replies, xml ) Need Help??


in reply to Re: Open a folder
in thread Open a folder

Your use of a global filehandle 'FH' inside a loop isn't a great idea. If the open fails then the nested while loop will use the already open handle FH which was left open to whatever file was opened last. Also since you've taken the trouble to define $dir why not use it when you open the file?

open (my $fh,'<',"$dir/$filename") or die " ... $!";

Another thing to watch out for is the directories '.' and '..'. Your code will pass these into $filename and attempt to open them. Use the file test -d $filename to skip directories. Or use -T $filename to find text files and ignore everything else.

A final suggestion is to use indentation inside loops and control blocks to help you keep track of the open and close curly braces.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-19 11:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found