elusion has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: loading
by btrott (Parson) on Jul 08, 2000 at 07:55 UTC | |
You wrote: This is wrong. Why do you have the || there? The || has higher precedence than the comma, so you're actually OR-ing "location.txt" with the die statement. "location.txt" will always be true, so that die will never get invoked, even if the open fails. Which is, I presume, when you wanted it to be invoked. Instead, use something like this: This will die if the open fails. | [reply] [d/l] [select] |
|
(jcwren) RE: loading
by jcwren (Prior) on Jul 08, 2000 at 17:11 UTC | |
This program won't do what you want for a number of reasons: So, with all this in mind, here is a version that should do what you want. It works on my NT 4.0/SP6a system using Perl 5.005_03, with no problems. (side note here: The actual path to the perl executable is irrelevant. However, you need *something* there so that the compiler picks up the -w flag. Don't be concerned that there is no '/usr/bin/perl' path on your system.) Why does this work, you might ask, after telling you that system() won't return until the called program completes? Because we're taking advantage of a little known fact that the 'shell' (such as it is) supports the 'start' keyword, which allows processes to be detached from the calling shell. The first parameter is the name of the program in the DOS box, and the second parameter is the program to execute. We technically could leave the first one blank, but I chose not to as I was debugging, and I saw no reason to leave it out. Supposedly, we could have omitted it, and used the /PGM switch, but I was getting errors. Since adding the window name fixed it, I didn't have any reason to pursue it any further. In this version, chomp() is required because the 'shell' gets very upset if you pass a carriage return into it. What you'll end up with is 3 open DOS boxes, with the window name as the name of the program you're trying to execute. Hopefully, this should do what you want. For testing, I have to change the names of the paths, and I don't have AIM installed (I used FreeCell instead), but I do have the rest. It all started up for me, just fine. Hopefully, it will work for you. --Chris | [reply] [d/l] |
|
Re: loading
by jjhorner (Hermit) on Jul 08, 2000 at 07:37 UTC | |
Try wrapping your code in tags. As Ozymandias said, use strict and -w. Also, if you are going to report an error, you might want to know why the error occurred: use $! to report the error message. I heard someone say once that you should use all caps to differentiate filehandles from other words in your code. Why use "|| die" inside the parenthesis? Isn't it just fine outside of them? You should also error check your 'system' call, but since 'system' returns 0 as the successful response, use && instead of ||.
J. J. Horner Linux, Perl, Apache, Stronghold, Unix jhorner@knoxlug.org http://www.knoxlug.org/ | [reply] [d/l] [select] |
|
Re: loading
by Ozymandias (Hermit) on Jul 08, 2000 at 06:17 UTC | |
Try it this way. Others will add more changes.
| [reply] [d/l] [select] |