develooper Front page | perl.perl5.porters | Postings from November 2011

New "dot" feature

Thread Next
From:
Leon Brocard
Date:
November 2, 2011 13:57
Subject:
New "dot" feature
Message ID:
20111102205724.GA27352@gmail.com
Hello Porters,

I had a dream that Perl 5 had moved from using -> to using . like most 
modern languages. And moved the existing . for concatenation to ~ like 
Perl 6. Then I wrote the code and was shocked how tiny it was.

I have this in the leonbrocard/dot branch, but is is really one commit:

  http://perl5.git.perl.org/perl.git/commit/0c1fbeee

It's a very small tokenizer patch which interacts with a new "dot" 
feature. Then you can do things like:

  use feature qw(say dot);
  use CGI;
  my $q = CGI.new;
  say ref($q);
  say $q.blockquote(
    "Many years ago on the island of",
    $q.a({href=>"http://crete.org/"},"Crete"),
    "there lived a Minotaur named",
    $q.strong("Fred.") ,
  ),
  $q.hr;

  my $arrayref = [1,2,3,4,5];
  say $arrayref.[-1];
  my $hashref = {a => 1, b => 2};
  say $hashref.{b};

  say "Hello" ~ "world";

I think this is quite a cute example of how features can do neat little 
tricks. There may be complicated interactions which break things in 
ways I haven't thought about, but it seems like a tiny patch that 
doesn't seem to slow parsing down. I'm not entirely sure that I'm 
proposing this seriously, but...

What do you think?

Cheers, Leon.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About