![]() |
Perl script not running correctly
Hi,
a friend had a perl script written for him, but he cannot get it to work in Leopard. Being only a little more mac savvy than he is I told him I would see if I could get it to run. I use the terminal to run the script and I don't get any errors, but nothing else happens either. Was hoping that somebody could be kind enough to point me in the right direction as to what the problem might be. The code is as follows: Code:
#!usr/bin/perlChris |
The first thing I notice is that you omitted the first slash in the path to 'perl' - you have:
#!usr/bin/perl when it should be: #!/usr/bin/perl See also the section on running scripts in this Unix FAQ and check that you have the correct line-endings (Unix-style end-of-line characters) |
Quote:
thanks for taking the time to respond! I added the first slash and still no luck. I then changed the line ending from for($x=0;$x<=500;$x++){print "Content-Type: text/html\n\n"; to for($x=0;$x<=500;$x++){print "Content-Type: text/html\r"; still didn't do anything. Might you have any other suggestions? Chris |
I'm not prepared to debug the script for you.
Instead, I suggest that you start at the beginning and learn enough to be able to debug it yourself. E.g. Start with the following small Perl script. Make sure that you can run it and it works - it should print "Hello" in the Terminal window. Then work up from there. Code:
#!/usr/bin/perl |
I'm not a perl guy, but I noticed you didn't actually say what was wrong. Just that you "can't get it to work". Whenever you need help with code, you should always state the higher-level goal (what task you're trying to accomplish), the intention of the code, the expected result of the code, the actual result of the code, and the steps you took to use the code.
http://catb.org/~esr/faqs/smart-questions.html |
Also, is this script some sort of hit count increaser for some MySpace crap? If so, that's pretty sad.
Code:
my $url = "http://media.myspace.com/services/media/mediahitcounter.ashx?i=MIGdBgorBgEEAYI3WAPYoIGOMIGLBgorBgEEAYI3WAMBoH0wewIDAgABAgJmAwICAMAECIH%2fybI3prlTBBCGjZWfM3HUnwwUAA997FvMBFARqytmu%2bmAgQcJrCSpYXUvtI8UmTld7pfXS9Y8JWvoxSWKbj8VPUZRScii2Jnoe71fp1EWwshGRapexehQREzrFfOUD0aQFr9CZJbhQEjeGQ%3d%3d"; |
Quote:
|
no luck with printing hello in the terminal. No error message either.
|
Read the section on running scripts in that FAQ I referred to above.
|
Mikey-San
sorry, I am not a programmer so I can't tell if the code is a hit count increaser. All I know is he asked if I could get the code to run on my mac because he couldn't on his so that is what I am attempting to do. |
Hayne,
I read the section on running scripts. I made it executable, I checked that it was executable , ran the script and still nothing happened. Below is what I typed in the terminal and the result: Macintosh:~ applemac$ chmod +x ~/Scripts/hello.pl Macintosh:~ applemac$ ls -l ~/Scripts/hello.pl -rwxr-xr-x@ 1 applemac applemac 32 Feb 18 14:40 /Users/applemac/Scripts/hello.pl Macintosh:~ applemac$ ~/Scripts/hello.pl Macintosh:~ applemac$ |
Being helpful to friends by running code you don't understand, even after admitting you aren't going to be able to help them make it work (since you don't know what it's supposed to do, etc etc) is a pretty risky way to learn. Hayne is pretty wise to suggest learning how to make the world's simplest script work first before trying to fix other's code.
Example: If I had a slightly evil streak, I'd ask my friends to try a script for me, and that script would give me root access to their machine, including complete control over downloading illegal files and randomly changing the contents of various documents the user had saved. |
dmacks,
understood. I am not trying to be nefarious here and obviously I can't help him with his code. But now I am just bugged because I can't figure out how to run the simple code that Hayne gave me, even after reading the section on running scripts. It's a bit frustrating, but I don't give up easily. |
Perhaps he should post here, then, so everyone can stop playing the telephone game.
|
What do you get from the following commands:
which perl perl -v Trevor |
trevor,
Macintosh:~ applemac$ perl -v This is perl, v5.8.8 built for darwin-thread-multi-2level (with 1 registered patch, see perl -V for more detail) Copyright 1987-2006, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. |
and which perl
Macintosh:~ applemac$ which perl /usr/bin/perl |
What text editor are you using for your script?
Trevor |
trevor,
I am using TextEdit |
Quote:
|
Quote:
* If there's some weird platform out there that uses some exotic line-ending scheme, Perl probably won't understand it unless Perl has already been ported to it. This is not the case for Unix (Mac OS X) and Windows. |
Now I am confused. Do I need to worry about line endings in this script or not?
#!/usr/bin/perl print "Hello\n" |
Quote:
|
Quote:
Another thing to try would be the following: Code:
perl -e 'print "hello\n"' |
Quote:
You always need to have Unix-style line-endings in any script files you want to run as if they are executables - i.e. by just typing the name of the script file. Just make things easier on yourself by running the one-line Perl script I supply in the Unix FAQ and you will be sure that your script file has the correct line-endings. |
Quote:
Here's the shell session I tested with: Code:
Last login: Sun Feb 17 05:33:58 on ttys000When I ran perl manually, passing it the name of the script, Perl parsed and ran it correctly. |
Quote:
|
Quote:
Because the exec function can't find the interpreter listed, it passes it off to the shell to try. The error message I posted is from bash, not the kernel. To illustrate: Code:
avi-shevins-computer:~ avi$ cat mooIt can also be shown that the exec function does not treat a carriage-return (the first character DOS uses to indicate end-of-line) as a whitespace character. Here is the same script I posted above, but with a parameter added to the interpreter invocation (-w turns on warning mode for Perl): Code:
avi-shevins-computer:~ avi$ cat test.pl |
Quote:
|
Quote:
|
(Offtopic)
On the subject of funny stuff, see post #17 of this old thread: http://forums.macosxhints.com/showthread.php?t=12881 |
Quote:
|
What's wrong is that it was posted 07/01 and not 04/01, Hayne. :p
It also occurs to me that the original script doesn't necessarily produce output. Make the last line print "done"; then run it. Thinking I should have been more descriptive in where I was going. "I use the terminal to run the script and I don't get any errors, but nothing else happens either" HTTP::Request::Common should echo back an error if it can't get a dns entry for the site. it should echo back if it does and connect properly. but what if it doesn't connect at all? As in gets a host name but times out trying to connect? What if the script is doing something, but you have it in a condition where there is no output? Stick some print statements in and see where it dies? By the way, your script works exactly as posted (with the path to perl correction noted above) on my leopard computer, exactly as it should. |
Quote:
:D |
| All times are GMT -5. The time now is 10:17 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.