My first Perl

chevy

Marvelous Da Vinci
Staff member
Mod
I tried a first Perl script today. I need some help to control the output.

The script is the following:

#!/usr/local/bin/perl

print "Hello World !";


It is placed in a file named

hello_world.pl

its permissions are changed to 777

when I call

perl hello_world.pl in Terminal I have no output (neither in the terminal window nor in the Console).

How do I change that ?
 
Hi,

try to use the following (in Terminal.app) to determine where exactly your perl executable is

which perl

In a "normal" Mac OS X it should (afaik) give you the following output:
/usr/bin/perl
So you might want to try and change your script as shown below:
#!/usr/bin/perl -w
print "Hello World!\n";

The "-w" switch tells perl to print out warnings, "\n" prints out a new line after "Hello World!", so it is easier to read.

To check the syntax of your script , type:
perl -c myperl.pl

If that does not produce any erros type
perl myperl.pl

This should do the trick (normally).

Hope I could help
 
I've found my mistake, thanks !

I used BBEdit and saved with Mac end-of-line instead of UNIX end-of-line !

Original:
***> more hello_world.pl
#!/usr/bin/perl^M^Mprint "Hello World !/n";


Correct:
***> more hello_world.pl
#!/usr/bin/perl

print "Hello World !\n";
 
Back
Top