13 ms·
Differences Between Perl 5 and Perl 6
- Paul_S 11y agoOne thing that bugs is that perl5 code could potentially run with perl6. Is there any mitigation for that?
- jayvanguard 11y agoIt was explicitly not a design goal to be backwards compatible. "In exchange for breaking backwards compatibility, at least at the language level, Perl 6 offers plenty of high-powered language concepts that Perl 5 didn't support..." http://www.perl.com/pub/2006/01/12/what_is_perl_6.html http://www.perl.com/pub/2006/01/12/what_is_perl_6.html
- maw 11y agoThat's not what I read the GP post as saying though. Rather, that the perl 6 interpreter could run code written as perl 5 (and never ported). With their different semantics, the results would be unpredictable and often undesired.
- kylebgorman 11y agoFrom this document, the chance that a perl 5 script is syntactically valid (but semantically different) perl 6 is awfully low. Now if the errors that arose said that you might be trying to execute perl 5 as perl 6, that'd be cool ;)
- donaldihunter 11y agoThere are numerous error messages that highlight perl 5 isms e.g. > say $#array; ===SORRY!=== Error while compiling <unknown file> Unsupported use of $#variable; in Perl 6 please use @variable.end and package foo; ===SORRY!=== Error while compiling <unknown file> This appears to be Perl 5 code. If you intended it to be Perl 6 code, please use a Perl 6 style declaration like "unit package Foo;" or "unit module Foo;", or use the block form instead of the semicolon form.
- amyjess 11y agoYes, these suggestions are among my favorite things about Rakudo. There are a lot more, too. Another example: > 1 == 1 ? "sane" : "insane" ===SORRY!=== Error while compiling <unknown file> Unsupported use of ? and : for the ternary conditional operator; in Perl 6 please use ?? and !! at <unknown file>:1 Or: > loop(my $i = 0; $i < 10; $i++) { say $i } ===SORRY!=== Word 'loop' interpreted as 'loop()' function call; please use whitespace around the parens at <unknown file>:1 Easily the nicest error reporting I've seen in a compiler.
- cytzol 11y agoAny Perl 6 code will have to include a `use v6;` instruction at the very top of the file, so there's no chance of Perl 5 code being confused for it. Is this what you mean? EDIT: this was completely wrong, see below.
- colomon 11y ago`use v6;` is not mandatory in Rakudo. Off the top of my head, I don't think it's mandatory in theory in Perl 6, either. However, it is widely used to mark Perl 6 code, because it gives you a nice clean error message if you accidentally try running it in Perl 5.
- cytzol 11y agoOh! I could have sworn it was necessary. My bad.
- perlgeek 11y agoYou should declare the version of your code. 'use v6;' for Perl 6 code (more specific versions will come up soon), and "use 5.014" for Perl 5.14, for example. This will give good error messages when trying to run your code with the wrong compiler.
- manuu 11y agoEverything is a reference! Nice!
- whyever 11y agoNot really if you car about efficiency.
- baudehlo 11y agoThe opposite is true. In Perl 5 passing a hash to a function requires mallocing a new shallow copy of that hash. In Perl 6 this would be the equivalent of passing a reference to the hash, which would only require mallocing a scalar.
- VLM 11y agoNote that its more or less "how to write perl 5 in perl 6" Sorta like the old F2C, Fortran to C, converter. You don't get idiomatic C, but you do get a fortran program that compiles and runs as a C program, more or less. Some parts of perl6 are annoyingly urbit-y, come on, you guys just had to rename ARGV and rename scalar and the for-foreach transition is ridiculous. I suspect at least a decade of people pointing at items and verbally calling them scalars and so on. Urbit is cool but is most famous for feeling the need to rename everything. Here's a slide stack for going from MOOSE (more or less the most popular "real" perl5 OO implementation, technically an "add on" for perl5 although many people will only program perl5 with MOOSE) to perl6 OO. At least toward the middle there are adjacent slides of "this is how you do it in MOOSE" "this is how you do it in perl6" http://www.slideshare.net/lichtkind/p6-oo-vs-moose-moo http://www.slideshare.net/lichtkind/p6-oo-vs-moose-moo I'd like to read a book titled something like "Modern Perl; For Perl 6.0" The transition will be such fun; I have some business logic libraries where I'll have to replicate behavior and test suites simultaneously for awhile in MOOSE/5.0 and in 6.0. (response to unfortunately hellbanned berntb question about replication, the codebase is huge and interrelated and can't be forklift upgraded all at once; its already non-trivial to do stuff in both perl and scala, and now it would be perl5 perl6 and scala all more or less interoperating)
- berntb 11y agoIt might be too much stress or too little coffee, but I don't understand the last part. Why would you need to replicate behaviour and tests? You mean it will take time before you trust the "use Perl 5 code in Perl 6" bridge that is worked on, so it isn't enough to run the Perl 5 tests and then use that code in Perl 6? (Or you think there will be bad interactions with Moose and Perl 6 OO?) Edit: Huh, I was shortly un-hellbanned and am Hellbanned again since the previous comment didn't live up to some interesting-level standard? :-)
- amyjess 11y ago> Edit: Huh, I was shortly un-hellbanned and am Hellbanned again since the previous comment didn't live up to some interesting-level standard? :-) Maybe your comment got rescued by someone using the new vouch feature?
- alricb 11y agoSo what you're telling me is that perl no longer automatically applies flatten to nested lists? Yay!
- SapphireSun 11y agoThat was never a problem you just used: $x = [ [1], [2], [3] ]; Instead of: @x = ( (1,), (2,), (3,) ); I always found it quite convenient to be honest.
- Someone 11y agoWas: my $len = length($string); Now: my $len = $string.chars; My intuitive interpretation of that syntax would be "given a string, return a sequence containing its characters, in order". Or is that overlading on return type, and do you get the behavior I would find intuitive if one assigns to an array? Even if that is true, I find that ugly. I would prefer more explicit code, for example my $len = $string.chars.#; Similarly: Was: $#array+1 or scalar(@array) Now: @array.elems (All IMHO)
- rihegher 11y agothis is a typo error actually: Now: my $len = $string.length; http://doc.perl6.org/type/Str#method_length http://doc.perl6.org/type/Str#method_length EDIT: I don't see any contact section on their page to let them know
- ksherlock 11y agomethod length Perl 6 does not have a length function. See chars or elems.
- nemo 11y agolength is gone. See: http://design.perl6.org/S29.html#Obsolete_Functions http://design.perl6.org/S29.html#Obsolete_Functions "length() This word is banned in Perl 6. You must specify units. In practice, this probably means you want Str.chars(), although it could be Str.bytes(), or even something else. See S32-setting-library/String for details."
- rcthompson 11y agoThat's an interesting design decision, and I suppose it solves the Python problem of "I want to operate on any iterable, except for strings which are technically iterables but I want to treat them as atomic elements." (Incidentally, does Python 3 have a solution to this problem?)
- rihegher 11y agoSorry about that, I've jumped a bit too fast on that one
- Diederich 11y agoI really like how the various try related constructs, for instance, CATCH, are lexically scoped inside the overall try block. This is a very logical and useful simplification I think.
- acqq 11y agoTo reuse the recent slogan, the only thing that changed is everything. It's a new language with its own internal logic. I used (and still use) Perl 5 because it made some specific things easy to make (various processing of data). I still don't know for which kind of tasks Perl 6 is the best choice. But maybe the language is simply too young for it to be obvious?
- Diederich 11y agoPerl6 is really a strict supserset of Perl5 in this way. Perl6 is at least as good as Perl5 for everything Perl5 is good at. But Perl6 is way, way more than that.
- debacle 11y agoI'll probably be trouted by a Perl monk for saying it, but sometimes less is more.
- Diederich 11y agoHa, what happens when one is 'trouted'?? It's been a number of years, and I can't check right now, but I believe that the amount of code in Perl6 is actually less than in Perl5. The amazing power that is Perl6 naturally falls out of a whole lot of experience and fantastic design decisions. Not to mention several great implementations. I'm a big fan of 'less is more' as well. In this case, you're literally correct: Perl6 delivers a LOT MORE than Perl5 even though there's 'less to it'!
- gknoy 11y agoI expect it's based on the /slap emote in IRC. Wikipedia [0] has a page on it, from which I swipe the follwing: `When someone does something inadvisable that they had the experience and intelligence to avoid, you may likely see the suggestion that they be "trouted"` Trout slapping originated in 1995 with internet relay chat (IRC). While in an IRC chat room, the IRC client mIRC would allow users to enter the command: /slap Sam - Steve slaps Sam around a bit with a large trout 0: https://en.wikipedia.org/wiki/Wikipedia:Whacking_with_a_wet_trout https://en.wikipedia.org/wiki/Wikipedia:Whacking_with_a_wet_...
- makecheck 11y agoIn multiple organizations I have primarily seen Perl applied to very large, complex and established code bases that also make significant use of things like reading/writing Perl data structures. Simply put, there will not be any grand push to re-sigil every stored data structure and make massive, sweeping changes to nearly every line to end up with the same program that looks, if anything, arguably less intuitive. This shows a profound unawareness of how Perl 5 was actually used in practice.
- perlgeek 11y agoPerl 6 developer here. Perl 6 is not an automatic upgrade path from Perl 5. We don't expect anybody to rewrite huge amounts of Perl 5 code in Perl 6. Perl 5 is going to be maintained separately. We do provide tools to augment Perl 5 code with Perl 6 code, and the other way around. There's Inline::Perl5 for Perl 6, and Inline::Perl6 for Perl 5.
- mirceal 11y agoIMHO Perl 6 will not catch on / be even mildly successful without a clear upgrade path from Perl 5. The ask for people to use Perl6 is a huge one given it's basically a completely different beast that just resembles Perl5. Without pointing out where Perl6 excels (in comparison to Python/Ruby not Perl5) this will probably be a non-starter for most people. (this is from somebody who did his fair share of Perl5 in the old days and would not go back to Perl5 / try Perl6 unless there would be an extremely clear differentiator that would make it worth it.
- kbenson 11y agoDid you actually look at Inline::Perl5[1] and Inline::Perl6? If may not be what you assume, and may change your opinion on whether an upgrade path is required. In short, Inline::Perl5 it's a way to interop cleanly with Perl 5 modules from Perl 6 using native Perl 6 syntax, and supports XS modules as well. I'm not sure I can imagine a more painless transition than what that allows. 1: https://github.com/niner/Inline-Perl5 https://github.com/niner/Inline-Perl5
- Grim_Reaper 11y agoPerl 6 have many symbols than Perl 5.
- Redoubts 11y ago>any two valid identifiers may be joined with a single ' to form a longer identifier Oh no.
- kstrauser 11y agoIt gets worse. "Hey, let's double down on weak typing!": http://examples.perl6.org/categories/cookbook/01strings/01-00introduction.html#Strings_as_numbers http://examples.perl6.org/categories/cookbook/01strings/01-0... print +"" ; # a num-ified empty string evaluates as 0 print "1" + 1 ; # 2 The opportunity for insidious bugs (for the benefit of not having to type 'int("1") + 1' those times when you really need to do that) is a terrible tradeoff, in my opinion. In before "but Python...!". Python is strongly typed. >>> "1" + 1 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: cannot concatenate 'str' and 'int' objects >>> 1 + "1" Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for +: 'int' and 'str'
- sp332 11y agoprint "1" + 1 ; # 2 This isn't new, is it? '+' is for addition, '.' is for concatenation.
- kbenson 11y agoIn Perl 5, yes. In Perl 6, ~ is for concatenation, '.' is for methods.
- kbenson 11y agoThis is not weak typing. Perl (both 5 and 6) use operators to define type context. It's entirely unambiguous whether you want to add something or concatenate strings because they are different operators. "1" + "1" # 2 "1" . "1" # 11 (~ to concatenate in Perl 6) 1 + 1 # 2 1 . 1 # 11 When you perform a string operation on a numeric type, it stringifies the number, when you do a numeric operation on a string, it numerifies the string (and warns if it can't be cleanly done). This isn't a typing problem, this is a commenting on language without actually knowing how it works problem. But that's nothing new, people have been doing that to Perl for a long time now.
- perlgeek 11y agoSee also http://doc.perl6.org/language/5to6 http://doc.perl6.org/language/5to6 (which is well maintained).
- nandhp 11y agoDo the changes to the regular expression syntax seem woefully under-publicized here? Was: $str =~ m/^\d{2,5}\s/i Now: $str ~~ m:P5:i/^\d{2,5}\s/ # :P5 indicates Perl5-compatibile regex syntax Was: $str =~ s/(a)/$1/e; Now: $str ~~ s:P5/(a)/{$0}/; # $1 is now $0 I actually find the change from $1 to $0 particularly disturbing, since that is well standardized and group 0 normally refers to the whole matched pattern (though Perl had to give it a different name and for some reason has always discouraged its use). They also provide no information here on the non-"Perl5-compatible" regexes, but they do talk about it a bit in Specification 5: http://design.perl6.org/S05.html http://design.perl6.org/S05.html There are some really interesting changes there, and we'll see what comes of this -- PCRE has become a de-facto standard, so I'm curious to see what happens as Perl moves away from "PCRE-compatible" syntax.
- acqq 11y agoIt seems "disturbing" is the good word here, as the kind of changes in the semantics or notation between Perl 5 and Perl 6 almost guarantees that most potential users would have to decide if they are going to reject using one or another: The need to "read differently" on the distant look similar code demands too much from the people who'd just like to "get the job done." What's that $1? Well it's the first match if it's Perl 5 but it's a second match if it's Perl 6. But don't worry, the other things in expressions also have sometimes other meanings.
- singingfish 11y agodon't use $1, use named captures or list assignment. qr/\$\d+/ is a oneliner thing or a code smell.
- nikatwork 11y agoIt's not a smell if you are doing an asston of text munging. Rather than write one ginormo regex I prefer a sequence of short actions. It's easier to debug and reason with.
- rurban 11y agoPlease see also cperl, a perl11 (=5+6), which is an extended perl5 variant with many perl6 features and syntax extensions. Only the perl6 syntax which violates perl5 cannot be supported. http://perl11.org/cperl/STATUS.html http://perl11.org/cperl/STATUS.html
- tedchs 11y agoAnd Perl6 has now invented its own word, "twigil"? Sigil was already a bad enough word. I used Per5 for a ton of production code years ago, and I've met Larry Wall and he is a brilliant and friendly person, but I am sad to say there is absolutely zero chance of Perl6 being adopted for a serious production software project, probably ever. It doesn't bring new capabilities, it's just different, and in a mostly-worse way.
- waynecochran 11y agoFor someone using Perl 5 as a replacement for bash scripting, is it worth making the jump to Perl 6? P.S. Why not name this language something new? -- Nicklaus Wirth didn't name Modula-2 Pascal 2.
- MaysonL 11y agoNicklaus Wirth didn't name Modula-2 Pascal 2 And that was a big marketing mistake. Do you think C++ would have been anywhere near as successful if it had been called Z?
- waynecochran 11y agoSo its a marketing decision? That's depressing.