Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: No such file or directory error

by Anonymous Monk
on Jan 10, 2013 at 08:59 UTC ( #1012616=note: print w/ replies, xml ) Need Help??


in reply to No such file or directory error

How come when I run this script ... it works just fine, but when I try using it in a bigger program it gives me the ":No such file or directory found at lingo4.pl line 508" error?

Because cwd is cwd and and readdir doesn't return absolute paths

If you opendir /a/s/d/f and readdir returns . .. foo.txt, then if you try to open foo.txt, you're trying to open cwd()/foo.txt not /a/s/d/f/foo.txt, so open will fail

you should have used File::Find::Rule

Because your bigger program is unwieldy

subroutine declarations are mixed with the main code -- write a single subroutine called Main, and confine the main logic of your program there -- see template at (tye)Re: Stupid question (and see one discussion of that template at Re^2: RFC: Creating unicursal stars

your code is 11 times as long as it should be -- you know how to make subroutines, so write subroutines, don't copy/paste the same code (same loops) 11 times

You're using short and/or meaningless variable names and putting the meaning in comments -- just use meaningful variable names :)

(sub folder) you already know how to use hashes, so don't code long if/else structures to return an integer, use a hash

(calling folder) dozens of while loops are not a substitute for a giant if/else structure -- which you wouldn't need if sub folder teturned a string instead of an integer

or just have sub folder take care of the printing

and while you're at it "folder" is a terrible name for a "sub" -- call it sub processFolder

If you have 14 minutes, watch String Calculator TDD Kata done in Perl , then rewrite your code in a similar fashion

my %korpusEng; sitKorpusInHash( \%korpusEng , 'korpusENG.txt' )l ...

Another example Out of memory and While replacements with excel XLSX application / Re^2: Out of memory and While replacements with excel XLSX application

good luck


Comment on Re: No such file or directory error
Download Code
Re^2: No such file or directory error
by davido (Archbishop) on Jan 10, 2013 at 09:06 UTC

    Another suggestion for OP, but relevant to this branch of the thread: Search for Michael Schwern's talk on Skimmable Code. It will help in refactoring the unwieldy concoction above into something more maintainable.


    Dave

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2014-12-22 03:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (110 votes), past polls