The perl interpreter takes text with perl command syntax, and creates bytecode out of them, and immediately runs this bytecode on the machine. While there are ways to make perl write this bytecode out to the filesystem for reuse, there is absolutely no need to do this. This is different from c, c++, which must be compiled with a compiler into binary code, which can then be run on the machine. Note, Java is somewhere between this. It is really an interpretive language, but the language has been standardized to force the text code to be 'compiled' into java bytecode using javac, and then manually run through the java interpreter. Now its time for us to appease the 'how to program' Gods by submitting ourselves to the requisite 'Hello World' program. The cool thing about perls interpretive aspect is that there are several ways to write and run perl programs (unlike the compiled or psuedocompiled languages).
- Run at the commandline (the perl 'oneliner'):
  shell>perl -e 'print "hello world";'
Note, running perl oneliners does require a little extra understanding of the way the shell 'interpolates' commands, eg, the shell will do things to this piece of text before passing it on to perl. Perl gives you some syntactic help for dealing with this: q, qq.
  shell>perl -e 'print q(Hello World); print "\n"' This is the same as print 'Hello World'; print "\n"; \n is a newline character
  shell>perl -e 'print qq(Hello $ENV{HOME}\n);' This is the same as print "Hello $ENV{HOME}\n". - As a text file passed to the perl interpreter directly: Perl files dont have special filename requirements. Any file that is text, and contains perl syntax, can be run through the interpreter. However, as a standard, perl applications end in .pl. Also, when we talk about perl modules, this is not true. They must end in .pm.
  shell>pico myFirstHelloWorld.pl
    print "Hello World\n";
  exit;
  [ctrl-O + ctrl-X to save and exit pico]
  shell> perl myFirstHelloWorld.pl
  shell> perl /absolute/path/to/myFirstHelloWorld.pl - As a normal unix command, using the magic-line (hash-pling), and chmod:
  shell> which perl
  /usr/bin/perl
  shell>pico myFirstHelloWorld.pl
    #!/usr/bin/perl
   print "Hello World\n";
  exit;
  <ctrl-e to exit pico>
  shell> chmod u+x myFirstHelloWorld.pl
  shell> ./myFirstHelloWorld.pl
  shell> /absolute/path/to/myFirstHelloWorld.pl
Comments (0)
You don't have permission to comment on this page.