james734 has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: ActivePERL is the devil?
by Corion (Patriarch) on Jun 07, 2007 at 20:06 UTC | |
Instead of blaming ActiveState, it helps to actually know about the module you use and the operating system environment your script runs on. The Shell module runs commands through the "current operating system shell", which, on Windows machines nowadays is cmd.exe, which uses the forward slash ("/") as command switch indicator and not as path separator. If you're afraid of using the well-tested modules to do file system operations from within Perl, most likely you will be able to use the backslash ("\\") as path separator on Windows machines. A far saner practice is to construct your file paths using the File::Spec module, that way you won't have to worry about the directory or file separators. | [reply] [d/l] [select] |
|
Re: ActivePERL is the devil?
by ikegami (Patriarch) on Jun 07, 2007 at 20:21 UTC | |
The problem you are experiencing has nothing to do with ActivePerl (or even Perl), but with the invalid data you are supplying to the various Windows commands you are using. (You owe ActiveState an apology.)
++Corion. This post is a more visual version of his post. | [reply] [d/l] |
|
Re: ActivePERL is the devil?
by shmem (Chancellor) on Jun 07, 2007 at 20:36 UTC | |
A use statement is performed once per module, and you pass it a list:
would be the right idiom. But perl? cd? AFAIK cd is a shell builtin, and perl has chdir. Probably the Shell->import() method will be invoked multiple times with your multiple use statements (I haven't tried), and your code thus is equivalent to
but why invoke the same method multiple times with a single element, if you can invoke it once with a list? But there are far more gotchas in your script, none of those have to do anything with ActiveState. E.g. you should use File::Spec to portably assemble directory and file names into a path. --shmem
| [reply] [d/l] [select] |
by ysth (Canon) on Jun 08, 2007 at 00:59 UTC | |
cd? AFAIK cd is a shell builtin, and perl has chdir.He was using cd to change the current drive, not the current working directory. I don't know much about windows perl, so can't say whether that's a reasonable thing to try or not, or whether perl's chdir would have done as well. | [reply] |
by runrig (Abbot) on Jun 08, 2007 at 01:07 UTC | |
He was using cd to change the current drive, not the current working directory. I don't know much about windows perl, so can't say whether that's a reasonable thing to try or not... chdir will change drives as well as directories. But as I said previously, 'system("cd ...")' won't stay cd'd in your perl program, just in the command shell. | [reply] |
by naikonta (Curate) on Jun 08, 2007 at 15:15 UTC | |
and your code thus is equivalent toMay be worse: Despite that only the first invocation of require compiles the module, it's still a sequence of invocations on the same function (require) with the same argument (Shell) within inside the very same file. Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy! | [reply] [d/l] [select] |
|
Re: ActivePERL is the devil?
by holli (Abbot) on Jun 07, 2007 at 19:52 UTC | |
holli, /regexed monk/ | [reply] |
|
Re: ActivePERL is the devil?
by Grundle (Scribe) on Jun 07, 2007 at 20:39 UTC | |
File::Copy was mentioned before. So then all you need is the "dir". I noticed you are using system calls, that is unnecesary for these type of commands. try the following finally to delete a file use the following If you want to set the context of your perl program to read from a particular directory without having to constantly put a $path + $filename then do the following you just got served lol | [reply] [d/l] [select] |
|
Re: ActivePERL is the devil?
by ferreira (Chaplain) on Jun 07, 2007 at 21:55 UTC | |
All the advices of the monks who replied to this node still apply. Some refactoring and moving filenames and tasks to configuration metadata driving the script could produce a much more robust and useful tool. But probably this isn't a priority or a need. So just two suggestions: (1) use / everywhere because Perl at Windows understand it very well unlike Windows itself; (2) maybe the Perl scripts "d:/perl/macc1" and "d:/perl/mmac3" can be converted to Perl modules with advantages to maintenance. | [reply] [d/l] |
by ikegami (Patriarch) on Jun 08, 2007 at 13:22 UTC | |
I've been told (on PerlMonks) that Windows system calls understand / just fine. It's the individual tools and shell commands that don't. In fact, it seems the shell tools understand / just fine if it's in quotes:
| [reply] [d/l] [select] |
by naikonta (Curate) on Jun 08, 2007 at 15:24 UTC | |
use Shell qw( perl ); # { local @ARGV = (...); do $filename; }Or, to ensure the use of the exact same copy of perl. Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy! | [reply] [d/l] [select] |
|
Re: ActivePERL is the devil?
by runrig (Abbot) on Jun 07, 2007 at 21:47 UTC | |
| [reply] [d/l] |
|
Re: ActivePERL is the devil?
by TGI (Parson) on Jun 08, 2007 at 21:00 UTC | |
I think this is what you are trying to do: Others have pointed out some of the problems with this script, system("cd d:") doesn't effect the rest of the progrem, etc. Others remain unnoted so far (recursive function call to answer(), use of & on function calls). Here's my UNTESTED rough cut at a rewrite. Here's what I already know is wrong with it. I haven't enabled taint checking for the file names. I don't untaint the file names. There is almost certainly a better way to run those perl scripts against the target file. The subroutines need block comments describing what they do. Script paths are hardcoded in the body of the script and not in variables or constants at the top of the file. The temporary and base paths are specified in list form, which isn't too familiar to many people, I should really use File::Spec to parse normal paths. Finally it is UNTESTED code that features the dangerous unlink command. Despite all this, it may be a useful starting point for you.
| [reply] [d/l] |
|
Re: ActivePERL is the devil?
by Anonymous Monk on Jun 08, 2007 at 02:36 UTC | |
| [reply] |