News for hackers. Stuff that matters.
Re:A little thing to love about Perl 6 and COBOL by erikb on Thursday February 05, 2015 @05:32AM (#9002555)
I'm certainly one who would rather learn Go or Ruby instead of Perl. Because I already know quite a lot Python and a little PHP, AWK and Bash I don't think I'll ever run into a usecase where learning Perl would be worth more than implementing a solution in e.g. Bash+Python+AWK. Around me the people all know these three languages better than Perl (or at least think so). Giving Perl6 a new name would certainly help in making it more interesting.
Re:A little thing to love about Perl 6 and COBOL by riffraff on Thursday February 05, 2015 @07:26AM (#9002842)
> I don't think I'll ever run into a usecase where learning Perl would be worth more than implementing a solution in e.g. Bash+Python+AWK.

that might be also because you are not familiar with perl6 though, a form of blub paradox.

I.e. are perl6 grammars better for parsing than anything available for python? Maybe or maybe not, but one needs to know them before being able to judge.

Re:A little thing to love about Perl 6 and COBOL by collyw on Thursday February 05, 2015 @08:18AM (#9003046)
I was playing around on hackerrank the other day as practice for a job interview using it. I haven't used Perl for 4 year, since I moved to Python, but all the problems i looked at seemed like they would be easier to do in Perl. Autovivificvation, and features built into the syntax just made certain things way easier. It was all doable in python, but you needed to do more checking.
Re:A little thing to love about Perl 6 and COBOL by erikb on Thursday February 05, 2015 @07:58AM (#9002954)
The reason I've written that comment is that I believe Perl lovers can, based on feedback like that, make better decisions about how to present their favourite language to the world. So if I would read a few articles on HN about how problems got solved with Perl in a way that Python wouldn't be able to, then I might start learning Perl soon. That's why I wrote that comment. Not for you guys to feel bad about your favourite language, but about helping you to present it better to people who don't know it yet.

The strong features of Perl that I know (which might be completely wrong): Regex and huge library. Both features are not distinct to Perl anymore though. Perl's regex might be a little better than Python's or AWK's but probably not enough to make it worth learning it.

And yes learning a new language to level that you not just know the syntax but also a few of the important libraries, blogs and developers is a huge task that takes several months. If you are not a student any more you really need to think hard before you commit to something like that. Sure there are people who just learn new languages for fun as a hobby. But that's not your target audience if you want your favourite language to become more popular.

Re:A little thing to love about Perl 6 and COBOL by maxlybbert on Thursday February 05, 2015 @11:51AM (#9004222)
> So if I would read a few articles on HN about how problems got solved with Perl in a way that Python wouldn't be able to, then I might start learning Perl soon.

That might have been the idea behind the ariginal article ("hey, Perl 6 has built in rational types").

Re:A little thing to love about Perl 6 and COBOL by b2gills on Thursday February 05, 2015 @04:00PM (#9006061)
One feature which I believe is distinctly available only in Perl 6 is it's grammar feature. ( think class/method based regular expressions that look similar to BNF )

As an example look at this Perl 6 grammar for JSON: https://github.com/moritz/json/blob/master/lib/JSON/Tiny/Gra...

Perl 6's best feature is that it combines many features from many languages in a way that allows combining them cleanly, and without any of them feeling like they were glommed on. (unlike Perl 5's object system which was inspired by Python's object system)

If you can get past the syntax differences from other languages, and program in it for a while, you may never want to go back to any other language.

If you can't get past the syntax, please say that you "don't like the syntax" instead of "it's unreadable" or "it's a write-only language" or "it's difficult to learn". ( I for one found it quite easy to learn, and can read it quickly. )

---

Really can you make all of the following examples clearer in any other single language?

  constant powers-of-two = 2,4,8 ... *; # an infinite deductive list

  # perhaps that would be more clear as:
  constant powers-of-two = 2, 4, 8, 16, 32, 64 ... *;

  # list of pairs using the zip meta-operator (Z)
  # combined with the pair constructor operator (=>)
  my @a = 'a'..'z' Z=> 0..*; # ( a => 0, b => 1, etc )
  my $new-password = ('a'..'z','A'..'Z',0..9).roll(12).join; # 'ygHIHbi4XgUV'

  # the zero in the following is to prevent an off-by-one error
  # when accessing by index
  # * + * creates a code ref that takes two inputs and numerically adds them together
  constant fibonacci-list = 0, 1, 1, * + * ... *;

   # takes about a second the first time it's accessed currently
  say fibonacci-list[10000].chars == 2090;

  # if you wanted it to look more like haskell you could write it like this:
  constant fibonacci-list = 0, 1, 1, &[+] ... *;

  my @dice-rolls := ('⚀'..'⚅').roll(*); # infinite list of dice rolls

  # deck of cards using the cross meta-operator (X)
  # and the string concatenation operator (~)

  my @deck = 2..10,<J Q K A> X~ <♡ ♢ ♣ ♠>;

  my @shuffled = @deck.pick(*);

  # ( .say ) is short for ( $_.say )
  # prints the first 6 numbers (0..5) each on it's own line
  for ^6 { .say }

  # prints the numbers 0..5 each on it's own line,
  # possibly randomized,
  # possibly each in it's own thread ( texas version )

  (0..^6)>>.say;
  (^6)».say; # ditto ( french version )

  # ( those were purposefully misusing an auto-threading list operator >> )

  # says a random number (1..5), 5 times out of 6
  if (0..5).pick -> $number { say $number }
  if (0..5).pick { say $^number } # ditto
---

That was just a sampling of the bread-and-butter constructs (some of which were used in a way that most people wouldn't use them). There are also operators for dealing with Sets for example. ( ⋃ and (elem) being two of them )

see: http://doc.perl6.org/

You can even create new operators the same way you define a subroutine ( That's all they are in the Rakudo implementation, for most of them. )

  # common factorial example
  sub postfix:<!> ( Int \n where * >= 0 ) is tighter(&infix:<*>) { [*] 1..n }
  say 5!; # 120
Re:A little thing to love about Perl 6 and COBOL by erikb on Friday February 06, 2015 @06:15AM (#9008525)
That is a quite convincing argumentation in favour of Perl6. Thanks! I really like this kind of code.
Re:A little thing to love about Perl 6 and COBOL by cafard on Thursday February 05, 2015 @09:16AM (#9003311)
It is possible that this is easier than I think in Python, but here is an example where Perl made my life (and various co-workers' lives) easier. A couple of years ago I needed to copy a bunch (between 1000 and 2000) posts from an old web site to a new one. This required parsing forms on the destination site, and also stripping out tags the new site did not support. The CPAN module HTML::TreeBuilder allowed me to do this quickly and without undue difficulty.
Re:A little thing to love about Perl 6 and COBOL by pwr22 on Thursday February 05, 2015 @07:44AM (#9002909)
Not everything is about utility for everyone