Search iEntry News

The MAIN Sub For Perl 6

By Taylor Gillespie
Expert Author
Article Date: 2010-08-24

Perl 6 very well may never fully supersede Perl 5 in the near future because they are engineered differently. Perl 5's maturity in the Unix-like environment make it a different tool compared to the current implementation of Perl 6 running on top of Parrot.

In all fairness, Perl 6 is not nearly production ready, but Perl 5 continues to feel and act like a "glue" while Perl 6 sets itself to be yet another language running in a virtual machine. Microsoft and Sun did it, so with so many spare computing cycles these days, spending some extra on a management layer seems to be no big deal. Regardless of production readiness, developing in Perl 6 can be a fun exercise.

Perl 6 adds some syntactic niceties. For example, using the @ sigil to signify an array and to access a scaler in the array; the $ is no longer used when accessing the value. Swapping sigils in certain contexts was a stumbling block for many beginners. The oft used qw() function, that surrounds values with quotes in an array, now has operator status in the form of Perl file handle operators "< >". But another nice, helpful improvement is the addition of the MAIN subroutine.

When initially invoking a Perl program from the command line, or any program for that matter, required and optional arguments are often needed for additional input needed for execution. The Perl 6 MAIN subroutine treats the command line invocation as a subroutine signature that correctly conforms to the MAIN subroutine's signature. It populates the MAIN subroutine's parameters with the corresponding name/value pairs from the command line. If the values on the command line do not mirror the signature of MAIN then a error occurs signifying a mismatch, a misuse. In this way, the MAIN subroutine helps facilitate the initial phase of processing command line arguments.

About the Author:
Taylor is a Staff Writer for WebProNews




Newsletter Archive | Article Archive | Submit Article | Advertising Information | About Us | Contact

PerlProNews is an iEntry, Inc. ® publication - All Rights Reserved Privacy Policy and Legal