14 char perl script


I just got an itch to be "clever" with perl, so I decided to try to write the smallest perl script I could. I put the requirement that it had to be executable from the command without calling perl directly (windows was outside the scope of this project :). It also had to output something somewhere to verify that it actually did something.

The first thing I did was think about what I could output to, like files, screen, speakers, force feedback joystick, etc... and decided that the most obvious would probably be the best choice, just print to the screen.

Since I don't know of a shortcut to the "print" command I had to accept those 5 characters. Then there's the two quote marks (single or double doesn't matter for final count). And don't forget the mandatory space after "print".

The next major issue was the "She Bang" line which on OS X would normally be "#! /usr/bin/perl" which I felt could be greatly simplified. So I added a symlink of "/p" pointing to "/usr/bin/perl". This did require modifying the standard system environment a little, but I felt the system environment could be reconfigured to suit this test since some linux/unix systems would have perl in /usr/bin/perl, or other locations anyway.

To modify the environment on OS X (probably 10.2+) issue this command in Terminal. You will have to have Administrative rights on your system.
sudo ln -s /usr/bin/perl /p

Then write this to a plain text file which you'll need to save as "p.pl"
#!/p
print 'h'

Notice that this page shows line returns after the "print 'h'" but they are not required and weren't counted to come up with 14 characters.

The last two steps are to change the file mode to be executable and then actually execute it.
chmod 755 p.pl
./p.pl

That's it. The shortest perl script I could come up with on short notice. It took way longer to blog it then to come up with it. Enjoy.

Wm