tag:blogger.com,1999:blog-13964332.post114271104861028217..comments2023-03-10T02:15:02.827-08:00Comments on Two Alpha: Perl BEGIN Blocks Considered HarmfulMatisse Enzerhttp://www.blogger.com/profile/03736762585596345292noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-13964332.post-40831093515984480952010-08-11T17:50:18.847-07:002010-08-11T17:50:18.847-07:00The primary case where I want to compile but not ...The primary case where I want to compile but not execute code is where I want to check the syntax and other compile-time rules. In these cases I might discover that there is a compile-time dependency on a module I have not installed, or that there is an undeclared variable while strict is enabled.Matisse Enzerhttps://www.blogger.com/profile/03736762585596345292noreply@blogger.comtag:blogger.com,1999:blog-13964332.post-34162568871287921092010-08-11T13:54:01.574-07:002010-08-11T13:54:01.574-07:00Good point! But when would there ever be a situati...Good point! But when would there ever be a situation in which you would want to compile a perl program and not execute it? Or in other words, in what situation would you ever feel it is safe to compile something but not safe to execute it? <br /><br />I'm not going to say that I agree with the usage of the BEGIN block in perl, but you probably shouldn't ever be in that situation where you would expect to be able to compile something "naughty" safely anyway... <br /><br />That being said, looking at perl from a higher level, I think it would be best to do away with the Begin block too... The problem right now though is that sometimes you need to run a little code to analyze your machine before you can call other pre-compiler functions. For example: <br />BEGIN{<br />$perl_location = "/depends/on/machine/";<br />} <br />"use lib $perl_location;"<br /> <br />In cases such as this, I think the ideal solution would be to eliminate the pre-compiler process all together, and just have one compilation process execute all functions in exactly the order that they are encountered. There should be no functions that should execute out of order from which the program is written. For example, the $perl_location variable in "use lib $perl_location" should not be evaluated first if it is put at the end of the program, but under current perl compiler rules, it does. <br /><br />We'll see if things change in perl6...Damian Greenhttps://www.blogger.com/profile/01093880316377189550noreply@blogger.com