Linux Format

Compatibil­ity with older Perl

-

By what you have seen so far, it should be obvious that existing Perl 5 code will need some changes in order to work with the Perl 6 compiler. As far as regular expression­s are concerned, if you have a complex Perl 5 regular expression that you want to use without changes in Perl 6, you can use the P5 modifier as in the next example: # Perl 5 code next if $line =~ m/[abc]/ ; # Perl 6 code that uses the P5 modifier next if $line ~~ m:P5/[abc]/ ; # New Perl 6 code next if $line ~~ m/ <[abc]> / ;

As you have already seen, the for loop is now only used to iterate over lists, so you will need to change your for loops to use them in Perl 6. Subroutine­s are also now defined using the sub keyword, and parameters in subroutine­s are readonly by default. The only way to change them is through using the following method:

If you’re not sure about a command or a function, you can always try it in the REPL and see if it works. ( Seeanexamp­le picturedon­bottom,p86.) As you can also see from the last command given, a lazy list doesn’t return inside REPL and you should terminate it manually.

Hopefully by now you’ll see that Perl 6 supports more programmin­g paradigms and has helpful and more informativ­e error messages and warnings than Perl 5. Perl 6 will be the dominant version very soon, so it’s worth learning more about the language and to start using it in your new projects is a no-brainer. We’d suggest, however, not to use it on the first big project that might come up, but begin with smaller ones first.

Newspapers in English

Newspapers from Australia