- Create a new Perl file containing the following:
print "hello world\n";
- Check the syntax with
perl -c filename
This will print hello world, even though "all" you did was compile the file.
What's going on here?
Well, BEGIN blocks get executed when Perl compiles the file.
If you run
perl -con a file that contains nasty code in a BEGIN block, you're screwed.
- You associate the filename extension .pm with a fancy Perl editor, like Komodo, or Affrus.
- You click on a link in your web browser.
- The web server redirects you to a URL for nasty_file.pm
- Your browser opens the associated editor and performs a"syntax check" by compiling the file
- The file's BEGIN block has naughty code in it...
So, keep in mind that "just compiling" Perl code may actually execute the code, so, be careful!
Here's a bug report on this subject that I filed for the Eclipse/EPIC Perl IDE.