Re: File::Path rmtree portability (works on OS X, fails on WinXP)

2007-09-28 Thread Ken Williams


On Sep 28, 2007, at 5:52 PM, Jim wrote:


# define build dir path
if ($runOS eq "win"){
$buildDir = ".PSF\\builds\\$version";
} else {
$buildDir = "/builds/$version";
}

# test for dir and remove if it exists
if ( -d $buildDir) {
   # using File::Path here for directory removal
use File::Path;
rmtree $buildDir,1,0;
}

Everything works as expected on OS X, but on WinXP, rmtree seems to  
fail with the following error...


Can't call method "rmtree" without a package or object reference


The problem is because of a different version of perl, not rmtree()  
itself.  One version of perl is interpreting your code as


   $buildDir->rmtree, 1, 0;

and the other as you intended:

   rmtree( $buildDir, 1, 0 );

If you add the parens explicitly, the problem should go away.

 -Ken



File::Path rmtree portability (works on OS X, fails on WinXP)

2007-09-28 Thread Jim
I have a bit of a curiosity here with a script I've been working on  
and am hoping that some others may have experienced and found a  
solution to a similar script portability issue.


The script in question is intended to run on OS X Perl and WinXP  
ActiveState PERL.

It seems simple enough

1) test if a directory exists
2) if so, remove it.

The $buildDir variable is set based upon which OS the script is  
running on.


For example:

# define build dir path
if ($runOS eq "win"){
$buildDir = ".PSF\\builds\\$version";
} else {
$buildDir = "/builds/$version";
}

# test for dir and remove if it exists
if ( -d $buildDir) {
   # using File::Path here for directory removal
use File::Path;
rmtree $buildDir,1,0;
}

Everything works as expected on OS X, but on WinXP, rmtree seems to  
fail with the following error...


Can't call method "rmtree" without a package or object reference

The rmtree method is the only place I seem to have trouble in my script.

Many other operations in the script that use the $buildDir variable  
to copy files into the build directory, or move it around, etc work  
both on OS X and WinXP.


I'm sure I can work around the problem by just using system(rm -r  
$buildDir) and system(del /S $buildDir) ... but I'd like to figure  
out if I'm actually doing something wrong with File::Path's rmtree or  
if the issue is more because of ActiveState PERL+Windows.


Any ideas out there?

Thanks in advance!

-jim-

---
"I gave you five of the best beers of my life...and what did you do?
You drank the sixth one too!"

4ABC 177B 8352 2D6B 1E10  DAE5 7865 34D5 3139 5D2D








Re: CGI.pm

2007-09-28 Thread Jeremiah Foster


On Sep 28, 2007, at 8:17 AM, Michael Barto wrote:

This seems like a flame, but I will try and answer your question.  
The reason why we are doing the HTML subroutines and so many others  
with key at the start (e.g. JSCript, DB, make, get). is mostly to  
support long term maintenance and parse out pieces of the code for  
a very large project (divide and conquer)
The modules libraries are maintained in a consistent manner. The  
variables $new_page and $from_page also are significant in this  
large code. It just helps the many people that have to touch this  
code have an easier path getting though any maintenance. The main  
program is nothing more than large set subroutine calls broken down  
in sections. The  subroutine calls are shared by many modules of  
the large project.




The "best practices" procedure is to use MVC. (Model, View, Control)  
- this provides separation of logic and presentation and  
significantly aids in the long term maintenance of your code. Look at  
Damian Conway's book; Perl Best Practices.


By not following best practices you run the risk of making your code  
write only. An experienced perl programmer would have a hard time  
reading it and re-factor it according to best practices.


Following best practices will significantly increase readability,  
maintenance, and quality of your code.


Jeremiah