ITworld.com
  Search  
ITworld Home Page ITworld Webcasts ITworld White Papers ITworld Newsletters ITworld News ITworld Topics Careers ITworld Voices ITwhirled Changing the way you view IT
What is Perl-6?
PERL --- 07/19/2001

Andrew Johnson

If you interact with the Perl community (via usenet or various Web sites) then you've probably heard about Perl-6 by now. But what exactly is it? Just another step in the versioning scheme or something more? I can't tell you exactly what Perl-6 will eventually look like, but I can tell you what it is and why. 

On this topic

The change from Perl4 to Perl5 was essentially Larry Wall's rewrite of Perl, and quite a bit was added to the Perl language at the time (but not much of the Perl4 language was changed). Perl-6 is to be, in Larry's words, "The community's rewrite of Perl".

Why rewrite Perl? Primarily, rewriting the core of perl (that's the perl source code, not the Perl language) will make it cleaner, faster, more extensible, easier for people to understand, and more accessible to other people who can then participate in the maintenance and development of perl itself. Larry also decided that there is no time like the present to investigate changes to the language itself. What isn't working out as well as we hoped? What additions would be useful? Thus, the Perl6 RFC process began and the greater Perl community submitted some 361 RFCs for language changes and/or additions.

Not all of the requests will be integrated into Perl-6 of course, but Larry and the team of Perl-6 developers will sift through them and use some in the new design. The process will take some time and you shouldn't expect to see a usable Perl-6 for perhaps another year. However, a few changes are apparent already:

  • Changing the usage of type symbols for variables
  • A new dereference operator (and concatenation operator)
  • Arrays and Hashes in scalar context
  • Typed variables?
  • Arrays and Hashes in scalar context

Changing the Usage of Type Symbols for Variables
Currently, as I'm sure you well know by now, we have three type symbols for variables: $ for scalars, @ for arrays, and % for hashes. However, you also know that these are symbols not strictly applied to variables, but to the type of thing you want to access. For example, to obtain the scalar value at index 3 of an array you use the $ symbol:

print $array[3];

In Perl-6 these type symbols will be exclusively used with their variable types, not the data type being accessed --- thus, the following will be the correct syntax:

$scalar = 12;
@array = (1,2,3); %hash = (name => 'andrew', beer => 'dark ale');

@slice = @array[1,2];
$scalar = @array[0];

%hash{'age','children'} = (37, 2);
print %hash{name};

As you can see, no matter what type of value you access you will use the variable type symbol (no more using @ for slices of hashes, and $ for scalar access of single array or hash elements).

A New Dereference Operator (and Concatenation Operator) The -> dereference arrow will be replaced with a dot (.). This makes Perl more similar to other OO languages with respect to calling object methods:

$foo = SomeObject->new();
$foo->some_method();

# becomes:

$foo = SomeObject.new();
$foo.some_method();

This means that the dot will no longer be used as the concatenation operator --- the new concat op will likely be the ~ character.

Typed Variables?
Yes, you will have the ability to declare variables as certain types (such as 'int' or 'constant'), or dimensioning arrays to a certain size. You won't be required to do this sort of thing, but it allows perl to optimize the code if you do.

Arrays and Hashes in Scalar Context
When used in a scalar context, hashes and arrays will return a reference to themselves. This means, to assign a reference to a hash or array we can do the following:

$a_ref = @array;
$h_ref = %hash;

But, don't worry about your habit of getting the length (number of elements) of an array by using it in scalar context, because now, an array reference in numerical context will return its length, and will return true if it holds any elements in a boolean context, so we can still perform the same sorts of array testing as we do now.

As you can see even from this short foray, Perl-6 won't simply be adding new stuff for us to use, but will be changing some of our currently familiar syntax. This is not a bad thing. The changes proposed so far make a good deal of sense and we should not fear them merely because we will have to make some adjustments to they way we currently do things. Also be aware that there will be some sort of compatibility mode so that Perl-5 programs can still be run (not to mention that versions of Perl-5 will not be disappearing anytime soon either).

There is a good more information about Perl-6, and you can stay abreast of its progress by checking out the following two sites:

http://www.perl.org/perl6/
http://dev.perl.org/perl6/

Next Week: Named parameters for subroutine calls.

 

Andrew Johnson works as a programmer/consultant and is the author of Elements of Programming with Perl from Manning Publications.



Advertisements
Sponsored links
Top 5 Reasons to Combine App Performance and Security
KODAK i1400 Series Scanners stand up to the challenge
Locate Hidden Software on business PCs with this free tool
Bring harmony to your mix of UNIX-Linux-Windows computing environments
 Home   Newsletters  PERL
www.itworld.com    open.itworld.com     security.itworld.com     smallbusiness.itworld.com
storage.itworld.com     utilitycomputing.itworld.com     wireless.itworld.com

 
Contact Us   About Us   Privacy Policy    Terms of Service   Reprints  

CIO   Computerworld   CSO   GamePro   Games.net   Industry Standard   Infoworld   ITworld  
JavaWorld   LinuxWorld  MacUser   Macworld   Network World   PC World   Playlist  

DEMO   IDG Connect   IDG Knowledge Hub   IDG TechNetwork   IDG World Expo  

Copyright © Computerworld, Inc. All rights reserved

Reproduction in whole or in part in any form or medium without express written permission of Computerworld Inc. is prohibited. Computerworld and Computerworld.com and the respective logos are trademarks of International Data Group Inc.